How to improve poor array performance using HHVM?

I tried to do some php 5.5 vs HHVM tests and got pretty good results with hhvm. However, bubble sorting performance on HHVM is pretty poor. I assume this has something to do with arrays. In the example below, when q = 1000 hhvm, it is almost 5 times worse than php 5.5. Since in both cases, since the test has been done so many times, I do not think that warm-up time should be a problem. In both cases, they work in fastcgi mode. In the case where q = 1000 php5.5 took about 200 ms to serve the page against almost 1000 ms for hhvm. I tried using splfixedclass, but its performance on hhvm was good too. Is there a special class or some special options that will improve array performance in hhvm?

I explained exactly what 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;
+4
source share
1 answer

One problem and one possible problem:

  • Put all your code inside the function. We do not use the JIT pseudo-network (code in the main body).
  • Run the code in a web request or use on the command line -v Eval.Jit=true. We turned off JITting for scripts, because they usually do not run for a long time, and the cost of a warm-up is greater than the cost of execution time.

.

function main() {
  // Do everything
}
main();
+10
source

All Articles