'Carmack Lines': Playing with Javascript
csbrooks6.github.io
csbrooks6.github.io
I really like the outcome with multiplication: http://play.golang.org/p/vF9aq6xF10
http://play.golang.org/p/O0F1FiAl6C
mod looks super interesting too.
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.
http://play.golang.org/p/VQ-gEFB271
(Sorry for the ugly code, I just copy/pasted and changed the example from mseepgood here, and I'm not a Go coder.)
There is a bug though that confused me a bit. The input has the value 1, but the hardcoded call of the draw function uses 7 on page load. I.e. line 66
draw(7);I'm a little surprised by the author's surprise. I am on an old 1GHz laptop right now, and on both firefox and chrome it runs so fast there is no noticeable delay between clicking and seeing a result.
Which seems reasonable because it's doing a pretty small computational loop that browsers are quite good at optimizing these days. Browsers have been competing on exactly these things for years.
((x ^ y) % 3) != 0
Other primes like 5 and 7 look interesting as well.
I think I know what I'll do for the rest of the evening.