How to improve poor array performance with HHVM?

Viewed 1260

I was trying to do some benchmarks of php 5.5 vs HHVM and was getting some pretty good results with hhvm. However the performance of bubble sort on HHVM is pretty bad. I am guessing it has something to do with arrays. In the below example when q=1000 hhvm is almost 5x worse than php 5.5. Since in both case since the test was run so many times I don't believe warm up time should be an issue. In both cases they are being fastcgi mode. In the case where q=1000 php5.5 took about 200ms to serve the page vs almost 1000ms for hhvm. I tried using splfixedclass, but its performance on hhvm was pretty bad too. Is there a special class or some special options that will improve array performance in hhvm?

I put an explanation of what exactly I did here: http://letschat.info/php-5-5-vs-hhvm-vs-node-js-benchmark-part-2/

$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;
1 Answers
Related