Petri Dish

The Game Of Life Javascript Benchmark

by Stephen Von Worley on January 30, 2013

Now, for your amusement, a pure HTML5+Javascript interpretation of computer science classic The Game of Life:

Why? Well…

Sixty-some years ago, the first computer operators punched binary machine code into paper tape. Programming was hard.

Soon, machine code begat assembly language, assembly language begat ALGOL, ALGOL begat CPL, then BCPL, B, C, and finally, C++. Thus equipped, in a single day, the ambitious geek could achieve what would’ve taken years of diddling ones and zeros. Life was good.

Around that time, the Internet made its debut, and then, OMFG…

The World Wide Web! Click a link, and your browser fetched the HTML from some far-flung server and rendered it up all nice and pretty. Like magic! Except that after a page loaded, it didn’t do much, but maybe animate a GIF or blink a tag.

Why so static? Because the dominant C/C++ paradigm excelled at producing giant, star-shaped pegs to the Web’s round, dialup-sized holes. Sensing the need, Sun gave us Java, which promised safe, bite-sized applets that you’d Write Once and Run Anywhere.

In practice, everything didn’t run quite everywhere. However, by 1999, both major Web browsers shipped with a high-quality Java virtual machine which would execute integer code nearly as fast as the equivalent C. By happenstance, I’d just founded an agency with a crackerjack engineering team, and we used Java’s “good parts” to create the first rich media banner ads, video-game style, by smashing bits, precomputing tables, and unrolling loops in ways that would make the Google Doodle blush.

Then, Macromedia’s Flash burst on scene, hypnotized designers with its whizzy tweens, and killed Java on the client. Overnight, the “interactive” Web degenerated into a stew of gratuitous transitions, dirt-slow ActionScript, and strange bugs that somehow survived each new Player release. Times were dark.

Now, a decade later, hallelujah… for the HTML5+Javascript duo heralds the second coming of efficient, general-purpose Web programming!

Hold on, not so fast… because while the latest desktop incarnations of Chrome/Safari/Firefox have Javascript performance pretty much nailed, what about lesser-endowed iPhones, Android eReaders, Internet-enabled toasters, and everything else?

To find out, I whipped together this Life implementation, optimized it for speed, and grafted on some benchmarking code. After iterating at full tilt for about ten seconds, it beams back timing data and details about the environment it ran in. With enough results, I’ll be able to better understand the universe of Javascript performance and tell you all about it.

So, please, drag your mouse | finger | sausage to become Conway, creator of tiny, cellular automata worlds. On as many different devices as you can manage.

And, of course, feel free to show it to your friends, so they can too.

Thanks, and ¡Viva la vida algorítmica!

Share → 
Next Article:
Previous Article:
Home: Read The Latest