Since my last post comparing Go vs Node vs HHVM, I decided I would do it properly.
First off, the previous test didn’t really sort the array one million times, it merely sorted once then iterated over the sorted array 999,999 times. Also, my previous test focussed on HHVM & PHP with OPCache and trusted the results from @jaxbox for the Go & Node. Given I’ve fixed the sorting of the array loop, I had to go and run the node & go tests myself. Thanks to my colleague at work for providing me a C version for comparison!
The code:
PHP:
C:
JS:
Go:
Java:
results.txt
C
$ time ./a.out
real 0m0.175s
real 0m0.172s
real 0m0.176s
real 0m0.170s
real 0m0.171s
=================
GO
$ time ./bubble
real 0m0.313s
real 0m0.313s
real 0m0.314s
real 0m0.313s
real 0m0.312s
=================
NODE
$ time node bubble.js
real 0m0.484s
real 0m0.489s
real 0m0.491s
real 0m0.489s
real 0m0.496s
=================
HHVM
$ time hhvm -v Eval.Jit=true hhvm.php
real 0m2.622s
real 0m2.657s
real 0m2.615s
real 0m2.662s
real 0m2.599s
=================
PHP 5.5 OPcache
real 0m30.421s
real 0m27.603s
real 0m27.695s
real 0m27.336s
real 0m27.706s
=================
Java
real 0m0.750s
real 0m0.717s
real 0m0.686s
real 0m0.709s
real 0m0.689s
Sorry for the crappy formatting of the results above. Maybe one day I shall put them in a table.
But basically you can see that in terms of bubble sorting; C > Go > Node > HHVM > PHP
However you look at it, I think it’s a no brainer to use HHVM!
Summary of best times:
Lang | Best Time |
C | 00.171s |
Go | 00.312s |
Node | 00.484s |
Java | 00.689s |
HHVM | 02.590s |
PHP 5.5.8 w/OPCache | 27.336s |
The improvement from HHVM is nice but given that everything else is still faster, the takeaway from this for me is that you should use anything but PHP 😉