3 ms·
> I’m kind of amazed at how fast Javascript executes, at least in Chrome. I’m iterating over 16,384 pixels every time you hit the button, and there’s no percept
by archgoon 13y ago
> I’m kind of amazed at how fast Javascript executes, at least in Chrome. I’m iterating over 16,384 pixels every time you hit the button, and there’s no perceptable delay at all, at least on my Macbook.
You have a computer that can execute 3 billion synchronous instructions per second* . Suppose that javascript was extremely inefficient (it's not), and required 10,000 machine instructions to iterate through the loop and set a pixel. The time to execute 10,000 machine instructions is about 50 milliseconds. I found that I didn't notice a delay until about 200 milliseconds (modifying the code with a setTimeout function). Such excessive waste would not be noticeable to a casual observer (you can run randomized A/B tests on yourself to investigate this :) ).
The work that has gone into v8 is very impressive. Arguably, however, the sheer brute force power of modern CPU's is more so. Don't underestimate it. :)
* Give or take. Setting pixels is an offscreen operation and should incur minimal I/O and scheduling overhead.