Home > Uncategorized > PHP 5.5 vs HHVM vs Node.js Benchmark part 3

PHP 5.5 vs HHVM vs Node.js Benchmark part 3

In the previous part hhvm was pretty slow doing bubble sort this was due code not being inside a function. THe key take away is always using functions when using hhvm especially for time consuming code.

if($_GET['q']!=""){
 $count = $_GET['q'];
} else {
  $count = 10000;

}

function  getRandom(){
        $random = array();
        global $count;

        for($i=0;$i<$count;$i++){
                $random[]=rand(1,100);
        }
        return $random;
}

function main(){
        global $count;
        $starttime = microtime(true);

        $array = getRandom();

     for($i=0;$i<10;$i++) {

        $a = count($array);
        $b=$a-1;

        for($j=0; $j < $a; $j++){
                for ($k=0;$k<$b;$k++) {
                        if ($array[$k+1] < $array[$k]) {
                                $t = $array[$k];
                                $array[$k] = $array[$k+1];
                                $array[$k+1] = $t;
                        }
                }
        }
        $array[$count/2]=rand(1,100);
     }

     echo microtime(true) - $starttime;
}

main();

Here are the results from the updated code.

q node php 5.5 hhvm
10 24.751 22.841 23.481
100 23.471 22.461 23.471
200 23.831 22.901 22.831
300 22.851 24.291 22.281
400 23.151 35.732 26.422
500 23.541 61.644 24.581
600 23.261 70.194 24.161
700 23.211 98.736 24.901
800 25.191 128.26 25.051
900 23.551 165.73 27.612
1000 28.352 233.01 26.492

bubble

As you can see hhvm keeps up with node once the code is updated. When count was increased to 10000 node was about twice as fast hhvm. The key to getting JIT performance from hhvm is ensure you wrap you code in functions. As you can see it increased hhvm performance almost 40x from the previous post.

Categories: Uncategorized Tags:
  1. Mike
    March 21st, 2014 at 17:21 | #1

    What I would be interested in is concurrency. Hit the server n times and see how long it takes for all requests to finish. Just a guess, but I would say HHVM will come out pretty much on top, as Node is single threaded parallel processing, while HHVM spawns a thead for each request.

    I don’t do Node. Let me know.

  2. May 6th, 2014 at 14:14 | #2

    WOW, no wonder wordpress is slow. haha, I tried wordpress with HHVM, and I got poor results. Load times were 10 times longer then php 5.3 with FCGI.

    I will do more testing myself, but good to know that it can be fast

  1. January 2nd, 2014 at 09:55 | #1
  2. January 2nd, 2014 at 09:59 | #2


+ 4 = nine