Ted Dziuba wrote a piece yesterday entitled Node.js is Cancer.
He contests that because a shitty Fibonacci number generator performs poorly Node.js is worthless. I contend that shitty Fibonacci generators are shitty in whatever language or framework.
Note: The Fibonacci number generator is incorrect. It should be
n <= 2 rather then
n < 2. I left it as Ted implemented to keep any comparison equivalent.
res.end with a number, it must be a String, Array, or Buffer.
Exact port of the Fibonacci number generator paired with SocketServer and SimpleHTTPServer. I’m not as knowledgeable about Python’s HTTP libraries so if there is a better one let me know.
The results really speak for themselves. It hardly matters that the implementation is inefficient. The close to the wire Node implementation soundly trounces the PHP and Python versions.
Node.js performed the best at 3.942 seconds.
josh$ time curl http://localhost:1337/ 165580141 real 0m3.942s user 0m0.004s sys 0m0.004s
PHP was the worst, taking almost a minute and a half to complete.
josh$ time curl http://localhost:8888/fibserver.php Number is: 165580141 real 1m22.709s user 0m0.004s sys 0m0.005s
The Python implementation was in the middle, but far closer in time at 49.223 seconds to the PHP implementation then the Node.js one.
josh$ time curl http://localhost:1339/ 165580141 real 0m49.223s user 0m0.002s sys 0m0.003s
apr_poll: The timeout specified has expired (70007)
I would love to hear from Ted what the “correct” way to write a web server to reply with on-the-fly generated Fibonacci numbers is.