performance measurements

Each table row shows performance measurements for this Hack program with a particular command-line input value N.

 N  CPU secs Elapsed secs Memory KB Code B ≈ CPU Load
105.605.6080,672532  99% 1% 3% 1%
1164.2064.2280,676532  100% 1% 1% 0%
12914.36914.5882,936532  21% 80% 1% 0%

Read the ↓ make, command line, and program output logs to see how this program was run.

Read fannkuch-redux benchmark to see what this program should do.

 notes

HipHop VM 3.3.0 (rel)
Compiler: tags/HHVM-3.3.0-0-g0a3cfb87b8a353fc7e1d15374f4adc413e37aba9
Repo schema: 9a391d9a03e15fccba1cde6d35c05b7cdd380238
Extension API: 20140829

 fannkuch-redux Hack program source code

<?hh // strict
/* The Computer Language Benchmarks Game
   http://benchmarksgame.alioth.debian.org/
   
   contributed by Isaac Gouy, transliterated from Mike Pall's Lua program 
*/

function initialized_vector(int $n): Vector<int> {
   $v = Vector {};
   for ($i=0; $i<$n; $i++){ $v[] = $i; }
   return $v;
}

function Fannkuch(int $n) {
   $p = initialized_vector($n); 
   $q = initialized_vector($n); 
   $s = initialized_vector($n); 

   $sign = 1; $maxflips = $sum = 0; $m = $n-1;  
   do {
      // Copy and flip.
      $q0 = $p[0];                                          // Cache 0th element.
      if ($q0 != 0){
         for($i=1; $i<$n; $i++) $q[$i] = $p[$i];            // Work on a copy.
         $flips = 1;
         do { 
            $qq = $q[$q0]; 
            if ($qq == 0){                                  // ... until 0th element is 0.
               $sum += $sign*$flips;
	       if ($flips > $maxflips) $maxflips = $flips;  // New maximum?
               break; 
            } 
 	    $q[$q0] = $q0; 
	    if ($q0 >= 3){
	       $i = 1; $j = $q0 - 1;
               do { $t = $q[$i]; $q[$i] = $q[$j]; $q[$j] = $t; $i++; $j--; } while ($i < $j); 
            }
	    $q0 = $qq; $flips++;
         } while (true); 
      }
      // Permute.
      if ($sign == 1){
         $t = $p[1]; $p[1] = $p[0]; $p[0] = $t; $sign = -1; // Rotate 0<-1.
      } else { 
         $t = $p[1]; $p[1] = $p[2]; $p[2] = $t; $sign = 1;  // Rotate 0<-1 and 0<-1<-2.
         for($i=2; $i<$n; $i++){ 
	    $sx = $s[$i];
	    if ($sx != 0){ $s[$i] = $sx-1; break; }
	    if ($i == $m) return array($sum,$maxflips);     // Out of permutations.
	    $s[$i] = $i;
	    // Rotate 0<-...<-i+1.
	    $t = $p[0]; for($j=0; $j<=$i; $j++){ $p[$j] = $p[$j+1]; } $p[$i+1] = $t;
         }
      }
   } while (true);
}

$n = (int)$argv[1];
list($checksum,$pf) = Fannkuch($n);
printf("%d\nPfannkuchen(%d) = %d\n", $checksum, $n, $pf);


 make, command-line, and program output logs

Sat, 25 Oct 2014 04:25:52 GMT

MAKE:
/usr/bin/hh_client
No errors!
0.02s to complete and log all make actions

COMMAND LINE:
/usr/bin/hhvm  fannkuchredux.hack 12

PROGRAM OUTPUT:
3968050
Pfannkuchen(12) = 65

Revised BSD license

  Home   Conclusions   License   Play