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

PHP 5.5 vs HHVM vs Node.js Benchmark part 2

In the first set of benchmarks I did I focused on recursive calls. In this second benchmark I focused on arrays. While scoured the web for various benchmarks I came across this one (http://jaxbot.me/articles/benchmarks_nodejs_vs_go_vs_php_3_14_2013 which shows that php is not very good at bubble sort. Bubble sort is a slow O(n^2) algorithm. The version I used is pretty much the worst way you can write it. It has to make n*n comparisons in total.

Check out part 3:

PHP 5.5 vs HHVM vs Node.js Benchmark part 3

$starttime = microtime(true);

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

}

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

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

$array = getRandom();

for($i=0;$i<10;$i++) {
        #$i=0;
        //while ($i<$a) {

        $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;
                        }
                }

                //++$i;
        }
        $array[$count/2]=rand(1,100);

}
print_r($array);
echo microtime(true) - $starttime;

Here is the javascript code:

var http = require('http');
 
var server = http.createServer(function (request, response) {
  response.writeHead(200, {"Content-Type": "text/plain"});
  var url = request.url.split("/");
  var num = parseInt(url[url.length-1]);
  console.log(num);
  var out = bubble(num);
  response.end(out.toString());
});
 
server.listen(80);
console.log("Server running");
 
function bubble(num){
 var starttime = new Date().getTime();
 var count=num;
 function getRandom(){
        var array=[];
        for(var i=0; i&lt;count; i++){
                array.push(Math.floor((Math.random()*100)+1));
        }
        return array;
 }
 
array= getRandom();
//var array = [3,4,1,3,5,1,92,2,4124,424,52,12];
 
for (var i = 0; i &lt; 10; i++) {
   for (var j = 0; j &lt; array.length; j++) {
        for (var k = 0; k &lt; array.length - 1; k++) {
            if (array[k+1] &lt; array[k]) {
                var t = array[k];
                array[k] = array[k + 1];
                array[k + 1] = t;
            }
        }
    }
    array[count/2]=Math.floor((Math.random()*100)+1);
}
//console.log(array);
console.log(new Date().getTime() - starttime);
 
return array;
}

The settings and versions used are same as the last post.

I used the following command: ab -n 100 -c 10 http://gimagesearch.com/array2.php?q=10

 

First the table

q node php55 hhvm
10 12.811 12.641 12.411
100 13.091 12.941 12.881
200 13.041 11.871 38.834
300 12.551 25.743 93.359
400 12.801 40.044 146.345
500 12.761 57.436 239.974
600 12.821 74.787 327.913
700 13.661 104.95 499.7
800 17.712 169.847 612.531
900 22.422 193.969 759.196
1000 27.793 207.591 996.4

array graph

As you can see hhvm performs quite poorly in this text. In this case hhvm is almost 5x times slower than php5.5 and nearly 36 times slower than node when q=1000. I also tried splFixedArray, but hhvm performed even worst with that class. I guess the way hhvm is handling arrays isn’t that great since in this benchmark all we are doing is iterating through arrays, comparing them, and swapping them. I am kind of disappointed by the results I saw with HHVM in this benchmark.

Update:

The hhvm performance can greatly be improved by making sure all code is in functions. please see part 3 for details.

PHP 5.5 vs HHVM vs Node.js Benchmark part 3

I have thank this post for helping me figure this out.
http://stackoverflow.com/questions/20859304/how-to-improve-poor-array-performance-with-hhvm/

Categories: Uncategorized Tags:


× 3 = twenty four