I've written a script to make snow fall and am trying to tweak the script to be able to make as many flakes fall as possible. I've tried unrolling the loop (with a combination of a few techniques), but the loop isnt long enough to make a dfference. I've tried splitting up the workload with two functions, one to update the first half of the flakes, and the other the remainder of the flakes, but that only made it worse (I guess because I was taking a multithreading approach and another setTimeout isnt another thread)
Here's where I update the position of the flake.
function move() {
for (i = (count - 1); i >= 0; i--) {
flakes.top = parseInt(flakes.top) + speeds;
flakes.left = parseInt(flakes.left) + wind_speed;
if (parseInt(flakes.top) > height || parseInt(flakes.left) > width || parseInt(flakes.left) < 0) {
reset(i);
}
}
move1_timeout = setTimeout("move()", 30);
}
The full source and working example is at <!-- m --><a class="postlink" href="http://joe.tgpr.org">http://joe.tgpr.org</a><!-- m -->
Any ideas?
I should probably say that the only apparent performance change is when I change the number of flakes. I have a looping method to control the wind, and taking that out doesnt effect it much.
I notice the performance because I'm in Linux and have a performance monitor docked to my panel. My browser is Phoenix, and im guessing isn't the fastest at executing javascript (its a derivitive of Mozilla and is only at version 0.5)
Using 20 snow flakes taks about 40% of my CPU. Using 5 flakes takes about 10%. My CPU is an Athlon 1.4Ghz
Thanks
- Joe
Here's where I update the position of the flake.
function move() {
for (i = (count - 1); i >= 0; i--) {
flakes.top = parseInt(flakes.top) + speeds;
flakes.left = parseInt(flakes.left) + wind_speed;
if (parseInt(flakes.top) > height || parseInt(flakes.left) > width || parseInt(flakes.left) < 0) {
reset(i);
}
}
move1_timeout = setTimeout("move()", 30);
}
The full source and working example is at <!-- m --><a class="postlink" href="http://joe.tgpr.org">http://joe.tgpr.org</a><!-- m -->
Any ideas?
I should probably say that the only apparent performance change is when I change the number of flakes. I have a looping method to control the wind, and taking that out doesnt effect it much.
I notice the performance because I'm in Linux and have a performance monitor docked to my panel. My browser is Phoenix, and im guessing isn't the fastest at executing javascript (its a derivitive of Mozilla and is only at version 0.5)
Using 20 snow flakes taks about 40% of my CPU. Using 5 flakes takes about 10%. My CPU is an Athlon 1.4Ghz
Thanks
- Joe