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!
$ time ./a.out
$ time ./bubble
$ time node bubble.js
$ time hhvm -v Eval.Jit=true hhvm.php
PHP 5.5 OPcache
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:
|PHP 5.5.8 w/OPCache
Lets start by saying, I was just curious as to how fast Go was compared to PHP. I knew it was faster, but wanted some benchmarks.
I found this great article by @jaxbot:
He then went on to dismiss PHP as it was too slow; so didn’t include it in the Go 1.1 benchmark test he did later:
Fair game I thought. Until a colleague pondered how fast HHVM would be as he’d recently installed it. Given how easy it is to install HHVM these days I decided to do my own benchmarking.
For Node & Go benchmarks, please refer to @jaxbox’s links above.
There is a minor difference in the code – and that is I am using a function to wrap the code. PHP is generally faster to execute code when it’s in a function, plus HHVM ignores code that isn’t in a function.
PHP 5.5 (opcache.enable_cli=0)
$ php bubble.php
Run 1: 24.121762990952
Run 2: 24.156540155411
Run 3: 24.948321819305
Run 4: 26.411414861679
Run 5: 24.790290117264
PHP 5.5 w/OPCache (opcache.enable_cli=1)
$ php bubble.php
Run 1: 24.675834178925
Run 2: 25.641896009445
Run 3: 26.468472003937
Run 4: 24.278208017349
Run 5: 24.843347072601
HHVM (PHP 5.5 OPCache)
$ hhvm -v Eval.Jit=true bubble.php
Run 1: 2.6463210582733
Run 2: 2.6204199790955
Run 3: 2.563747882843
Run 4: 2.9089078903198
Run 5: 2.6408560276031
Interesting is that OPcache didn't fair well in this bubblesort...
Now let's compare to the tests from @jaxbot - he had different hardware, so a direct comparison is almost meaningless.. BUT HHVM speaks for itself when compared to the Zend Engine.
|Avg of 5 trials
Hope that helps someone who wonders how good HHVM is?! 🙂
I finish with a quote from @jaxbox: "the same rules apply here as last time; take these with a lattice of Sodium Chloride, as the benchmarks tell us information, not answers."