Quantcast
Channel: Hacker News 50
Viewing all articles
Browse latest Browse all 9433

Turing Drawings

$
0
0

Comments:"Turing Drawings"

URL:http://wry.me/hacking/Turing-Drawings/


This is an asm.js fork of Maxime Chevalier-Boisvert's original page (see original blog post). The original code interprets the Turing machine; this code compiles it to asm.js.

(I also added the Faster/Slower/Pause buttons and the ring around the machine's head visible at slow speeds, moved the starting position to mid-canvas from upper left, and fixed a color-map entry.)

Some timings on my laptop (a ThinkPad X1 Carbon running Firefox Nightly (2013 March) and Chrome 26, on Windows 7) for a particular Turing machine:

(Branch master includes some improvements that apply just as well without asm.js: using local variables in the inner loop, compiling each Turing machine to a custom Javascript function, and skipping writes to the state or the grid where they're known to already hold the new value.)

The frame rate on this page should be pretty close to the original because in both versions it's limited by design, to keep the action visible and the UI responsive. I've upped the framerate while reducing the number of steps/frame to keep the speed roughly constant, to take advantage of the faster computation. (The code doesn't account for time spent on screen update or waiting on setInterval(), in either version.) You might prefer to leave the framerate untouched and reap the advantage as a cooler CPU. (N.B. this page chews up CPU even after the grid stops changing — the Turing machine is just rewriting the same never-changing bits.)

One more change turned out to be needed: calls to the inner loop run much larger chunks (50,000 steps instead of 5,000). Each call into an asm.js function takes about 2 msec (at this writing): at the original finer granularity almost all the time was going into the asm.js trampoline, not actually computing anything.

Examples (from the README). Because the original code doesn't notice when you click to a new #fragment on the same page, and I don't want to mess with it, I've made the URL trivially different from the one you probably came in to (www.wry.me vs. wry.me). Just go back to the wry.me page to click on another example.


Viewing all articles
Browse latest Browse all 9433

Trending Articles