Sunday, June 8, 2014

Node.js mandelbrot server

Node.js mandelbrot server

After trying in python and go, I thought I'd give node.js a try, to see how it performs against those two.

Once I found a png library for node.js, it was pretty easy to get working (definitely less to learn than the go version). It also performed pretty decently, being only about twice as slow as the go version.

The code's available here and I hope is pretty self explanatory. If you want to run it, use npm to install node-png then run the file. It should work with the html page from the python post.


After finding that everything seems faster than Python, I spent a bit of time optimizing the Python version, it no longer uses complex numbers but stores the real and imaginary parts in two separate images. It's still pretty readable. After doing that, the times were:

LanguageTime (s)

It's worth noting that these are the times for serial mandelbrot generation, both Python and go use multiple threads, but the node.js version doesn't (although still feels faster than the threaded Python version when run from the browser). Javascript isn't my language of choice (although it now seems fashionable to bash javascript-bashers) but it is nice to have a language that's literally on every computer, and that has had many man hours spent on optimizing the compiler to produce impressively fast code. 

1 comment:

  1. Im no expert, but I believe you just made an excellent You certainly understand what youre speaking about, and I can truly get behind that.
    Node JS training in chennai