Tuesday, October 16, 2012

A quick speed comparison between PHP, Node.js and native code. This is obviously an artificial benchmark. The code generates four random numbers between 0 and 100 and uses them as coordinates of two points on a plane, and then calculates the distance between them. This is repeated 10 million times. Only the loop is timed, so process startup time is not part of the timing. The results are:

PHP - 12.692 seconds
Node.js - 0.328 seconds
Native - 0.308 seconds

All tests were run on a MacBook Pro. PHP is almost 40 times slower than Node.js. Node.js is almost as fast as native code, which makes sense since it does just-in-time compilation.

Sunday, October 7, 2012

TL;DR - 1 million documents with readings across 20 sensors (1 reading per document), find the number of readings and their average per sensor. Aggregation framework does it in 4.1 seconds, map/reduce in 67.2 seconds, map/reduce with jsMode=true in 45.5 seconds, and reading all documents into PHP and doing it there takes 3.3 seconds. Conclusion - MongoDB's map/reduce has horrible performance for some reason.