2015-01-26

PHP/HHVM vs Go vs NodeJs BubbleSort Benchmark

So, I wonder about how good HHVM now, the code was taken from this post. My setup is 64-bit Linux 3.18.2-1, AMD A8-6600K, 16 GB RAM, Non-SSD disk, here's the best result of each implementation:

PHP 5.6.4

$ time php bench.php 
Array
(
    [0] => 1
    [1] => 1
    [2] => 2
    [3] => 3
    [4] => 3
    [5] => 4
    [6] => 5
    [7] => 12
    [8] => 52
    [9] => 92
    [10] => 424
    [11] => 4124
)
2.3711581230164
real    0m2.383s
user    0m2.373s
sys     0m0.010s

HHVM 3.5.0

$ time hhvm -v Eval.Jit=true bench.php 
Array
(
    [0] => 1
    [1] => 1
    [2] => 2
    [3] => 3
    [4] => 3
    [5] => 4
    [6] => 5
    [7] => 12
    [8] => 52
    [9] => 92
    [10] => 424
    [11] => 4124
)
0.13958597183228
real    0m0.414s
user    0m0.247s
sys     0m0.033s

Go 1.4.1
And yes, I include the compile time also for fairness.

$ rm bench; time(go build bench.go && ./bench)
removed ‘bench’
[1 1 2 3 3 4 5 12 52 92 424 4124]
23.027575ms
real    0m0.191s
user    0m0.150s
sys     0m0.033s

$ time ./bench 
[1 1 2 3 3 4 5 12 52 92 424 4124]
22.757741ms
real    0m0.024s
user    0m0.023s
sys     0m0.000s

NodeJS 0.10.35

$ time node bench.js
[ 1, 1, 2, 3, 3, 4, 5, 12, 52, 92, 424, 4124 ]
42

real    0m0.065s
user    0m0.060s
sys     0m0.003s

From what we could see (run duration - actual duration):
Go: 22ms - 24ms
NodeJS: 42ms - 65ms
Go (with compile duration included): 23ms - 191ms
HHVM: 139ms - 414ms
PHP2371ms - 2383ms