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
250,000Bad Output  1038   

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

Read k-nucleotide 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

 k-nucleotide Hack program source code

<?hh
/* 
   The Computer Language Benchmarks Game
   http://benchmarksgame.alioth.debian.org/

   contributed by Damien Bonvillain
   fixed by Isaac Gouy
   improved by Levi Cameron
   made about 8 times faster by Ludovic Urbain
   pcntl has a flat overhead of about 40ms on my VM, read_sequence takes about 10%
   PHP as HHVM/Hack by Isaac Gouy
*/


function read_sequence($id) {
   $id = '>' . $id;
   $ln_id = strlen($id);
   $fd = STDIN;

   // reach sequence three
   
   while (strpos($line, $id) ===false){
      $line = stream_get_line($fd, 64, "\n"); // returns faster when the length is too large
      if(feof($fd)){
         exit(-1);
      }
   }
   // next, read the content of the sequence
   $r='';
   while (!feof($fd)) {
      $line = stream_get_line($fd, 64, "\n");
      if (!isset($line[0])) continue;
      $c = $line[0];
      if ($c === ';') continue;
      if ($c === '>') break;
      $r.=$line;
   }
   return strtoupper($r);
}

function write_freq(&$sequence,&$seqlen, &$keys) {
   $map = array();
   $total=0;
   if(strlen($keys[0])==1){
      foreach($keys as $p){
         $map[$p]=substr_count($sequence,$p);
         $total+=$map[$p];
      }
   }elseif(strlen($keys[0])==2){
      //this is here only because substr_count does not count overlapping strings,
      // it can be replaced by anything counting overlapping strings and with better performance
      for($i=0;$i<$seqlen-1;$i++){
         $map[$sequence[$i].$sequence[$i+1]]++;
      }
      foreach($keys as $p){
         $total+=$map[$p];
      }
   }
   foreach($keys as $p){
      $map[$p]=( $map[$p] / $total ) *100;
   }
   uasort($map, 'freq_name_comparator');
   $r='';
   foreach($map as $key => $val) {
      $r.=sprintf ("%s %.3f\n", $key, $val);
   }
   return $r."\n";
}

function write_count(&$sequence,&$seqlen, $key){
   return sprintf ("%d\t%s\n", substr_count($sequence,$key), $key);
}

function freq_name_comparator($a, $b) {
   if ($a == $b) return 0;
   return  ($a < $b) ? 1 : -1;
}
$sequence = read_sequence('THREE');
$seqlen=strlen($sequence);
fclose(STDIN);

$jobs = array(
   array('write_freq', array('A','T','G','C')),
   array('write_freq', array('AA','AT','TA','TT','CA','GA','AG','AC','TG','GT','TC','CT','GG','GC','CG','CC')),
   array('write_count', 'GGT'),
   array('write_count', 'GGTA'),
   array('write_count', 'GGTATT'),
   array('write_count', 'GGTATTTTAATT'),
   array('write_count', 'GGTATTTTAATTTATAGT')
);

$tok = ftok(__FILE__, chr(time() & 255));
$queue = msg_get_queue($tok);

$parent = TRUE;
$count = count($jobs);
for ($i = 0; $i < $count-1; ++$i) {
   $pid = pcntl_fork();
   if ($pid === -1) {
      die('could not fork');
   } else if ($pid) {
      continue;
   }
   $parent = FALSE;
   break;
}
$result = array($i,$jobs[$i][0]($sequence, $seqlen, $jobs[$i][1]));
if (!msg_send($queue, 2, $result, TRUE, FALSE, $errno)) {
   var_dump("$errno");
   var_dump(msg_stat_queue($queue));
}

if (!$parent) {
   exit(0);
}

$results = array();
foreach($jobs as $job) {
   msg_receive($queue, 2, $msgtype, 256, $result, TRUE);
   $results[$result[0]] = $result[1];
   pcntl_wait($s);
}

ksort($results);
foreach ($results as $result) {
   echo $result;
}

msg_remove_queue($queue);

 make, command-line, and program output logs

Sat, 25 Oct 2014 19:53:31 GMT

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

COMMAND LINE:
/usr/bin/hhvm  knucleotide.hack 0 < knucleotide-input250000.txt

UNEXPECTED OUTPUT 

1,2d0
< 
< Notice: Undefined variable: line in /home/dunham/benchmarksgame/bench/knucleotide/knucleotide.hack on line 22

PROGRAM OUTPUT:

Notice: Undefined variable: line in /home/dunham/benchmarksgame/bench/knucleotide/knucleotide.hack on line 22
A 30.298
T 30.157
C 19.793
G 19.752

AA 9.177
TA 9.137
AT 9.136
TT 9.094
AC 6.000
CA 5.999
GA 5.986
AG 5.985
TC 5.970
CT 5.970
GT 5.957
TG 5.956
CC 3.915
CG 3.910
GC 3.908
GG 3.902

14717	GGT
4463	GGTA
472	GGTATT
9	GGTATTTTAATT
9	GGTATTTTAATTTATAGT

Revised BSD license

  Home   Conclusions   License   Play