Back to index

php5  5.3.10
Functions | Variables
bench.php File Reference

Go to the source code of this file.

Functions

 simple ()
 simplecall ()
 hallo ($a)
 simpleucall ()
 simpleudcall ()
 hallo2 ($a)
 mandel ()
 mandel2 ()
 Ack ($m, $n)
 ackermann ($n)
 ary ($n)
 ary2 ($n)
 ary3 ($n)
 fibo_r ($n)
 fibo ($n)
 hash1 ($n)
 hash2 ($n)
 gen_random ($n)
 heapsort_r ($n, &$ra)
 heapsort ($N)
 mkmatrix ($rows, $cols)
 mmult ($rows, $cols, $m1, $m2)
 matrix ($n)
 nestedloop ($n)
 sieve ($n)
 strcat ($n)
 getmicrotime ()
 start_test ()
 end_test ($start, $name)
 total ()

Variables

 $t0 = $t = start_test()
 $t = end_test($t, "simple")

Function Documentation

Ack ( m,
n 
)

Definition at line 100 of file bench.php.

                    {
  if($m == 0) return $n+1;
  if($n == 0) return Ack($m-1, 1);
  return Ack($m - 1, Ack($m, ($n - 1)));
}

Here is the caller graph for this function:

ackermann ( n)

Definition at line 106 of file bench.php.

                       {
  $r = Ack(3,$n);
  print "Ack(3,$n): $r\n";
}

Here is the call graph for this function:

ary ( n)

Definition at line 113 of file bench.php.

                 {
  for ($i=0; $i<$n; $i++) {
    $X[$i] = $i;
  }
  for ($i=$n-1; $i>=0; $i--) {
    $Y[$i] = $X[$i];
  }
  $last = $n-1;
  print "$Y[$last]\n";
}
ary2 ( n)

Definition at line 126 of file bench.php.

                  {
  for ($i=0; $i<$n;) {
    $X[$i] = $i; ++$i;
    $X[$i] = $i; ++$i;
    $X[$i] = $i; ++$i;
    $X[$i] = $i; ++$i;
    $X[$i] = $i; ++$i;

    $X[$i] = $i; ++$i;
    $X[$i] = $i; ++$i;
    $X[$i] = $i; ++$i;
    $X[$i] = $i; ++$i;
    $X[$i] = $i; ++$i;
  }
  for ($i=$n-1; $i>=0;) {
    $Y[$i] = $X[$i]; --$i;
    $Y[$i] = $X[$i]; --$i;
    $Y[$i] = $X[$i]; --$i;
    $Y[$i] = $X[$i]; --$i;
    $Y[$i] = $X[$i]; --$i;

    $Y[$i] = $X[$i]; --$i;
    $Y[$i] = $X[$i]; --$i;
    $Y[$i] = $X[$i]; --$i;
    $Y[$i] = $X[$i]; --$i;
    $Y[$i] = $X[$i]; --$i;
  }
  $last = $n-1;
  print "$Y[$last]\n";
}
ary3 ( n)

Definition at line 159 of file bench.php.

                  {
  for ($i=0; $i<$n; $i++) {
    $X[$i] = $i + 1;
    $Y[$i] = 0;
  }
  for ($k=0; $k<1000; $k++) {
    for ($i=$n-1; $i>=0; $i--) {
      $Y[$i] += $X[$i];
    }
  }
  $last = $n-1;
  print "$Y[0] $Y[$last]\n";
}
end_test ( start,
name 
)

Definition at line 361 of file bench.php.

{
  global $total;
  $end = getmicrotime();
  ob_end_clean();
  $total += $end-$start;
  $num = number_format($end-$start,3);
  $pad = str_repeat(" ", 24-strlen($name)-strlen($num));

  echo $name.$pad.$num."\n";
       ob_start();
  return getmicrotime();
}

Here is the call graph for this function:

fibo ( n)

Definition at line 179 of file bench.php.

                  {
  $r = fibo_r($n);
  print "$r\n";
}

Here is the call graph for this function:

fibo_r ( n)

Definition at line 175 of file bench.php.

                   {
    return(($n < 2) ? 1 : fibo_r($n - 2) + fibo_r($n - 1));
}

Here is the caller graph for this function:

gen_random ( n)

Definition at line 214 of file bench.php.

                         {
    global $LAST;
    return( ($n * ($LAST = ($LAST * IA + IC) % IM)) / IM );
}

Here is the caller graph for this function:

Definition at line 349 of file bench.php.

{
  $t = gettimeofday();
  return ($t['sec'] + $t['usec'] / 1000000);
}

Here is the call graph for this function:

Here is the caller graph for this function:

hallo ( a)

Definition at line 26 of file bench.php.

                   {
}

Here is the caller graph for this function:

hallo2 ( a)

Definition at line 41 of file bench.php.

                    {
}

Here is the caller graph for this function:

hash1 ( n)

Definition at line 186 of file bench.php.

                   {
  for ($i = 1; $i <= $n; $i++) {
    $X[dechex($i)] = $i;
  }
  $c = 0;
  for ($i = $n; $i > 0; $i--) {
    if ($X[dechex($i)]) { $c++; }
  }
  print "$c\n";
}
hash2 ( n)

Definition at line 199 of file bench.php.

                   {
  for ($i = 0; $i < $n; $i++) {
    $hash1["foo_$i"] = $i;
    $hash2["foo_$i"] = 0;
  }
  for ($i = $n; $i > 0; $i--) {
    foreach($hash1 as $key => $value) $hash2[$key] += $value;
  }
  $first = "foo_0";
  $last  = "foo_".($n-1);
  print "$hash1[$first] $hash1[$last] $hash2[$first] $hash2[$last]\n";
}
heapsort ( N)

Definition at line 251 of file bench.php.

                      {
  global $LAST;

  define("IM", 139968);
  define("IA", 3877);
  define("IC", 29573);

  $LAST = 42;
  for ($i=1; $i<=$N; $i++) {
    $ary[$i] = gen_random(1);
  }
  heapsort_r($N, $ary);
  printf("%.10f\n", $ary[$N]);
}

Here is the call graph for this function:

heapsort_r ( n,
&$  ra 
)

Definition at line 219 of file bench.php.

                              {
    $l = ($n >> 1) + 1;
    $ir = $n;

    while (1) {
       if ($l > 1) {
           $rra = $ra[--$l];
       } else {
           $rra = $ra[$ir];
           $ra[$ir] = $ra[1];
           if (--$ir == 1) {
              $ra[1] = $rra;
              return;
           }
       }
       $i = $l;
       $j = $l << 1;
       while ($j <= $ir) {
           if (($j < $ir) && ($ra[$j] < $ra[$j+1])) {
              $j++;
           }
           if ($rra < $ra[$j]) {
              $ra[$i] = $ra[$j];
              $j += ($i = $j);
           } else {
              $j = $ir + 1;
           }
       }
       $ra[$i] = $rra;
    }
}

Here is the caller graph for this function:

mandel ( )

Definition at line 46 of file bench.php.

                  {
  $w1=50;
  $h1=150;
  $recen=-.45;
  $imcen=0.0;
  $r=0.7;
  $s=0;  $rec=0;  $imc=0;  $re=0;  $im=0;  $re2=0;  $im2=0;
  $x=0;  $y=0;  $w2=0;  $h2=0;  $color=0;
  $s=2*$r/$w1;
  $w2=40;
  $h2=12;
  for ($y=0 ; $y<=$w1; $y=$y+1) {
    $imc=$s*($y-$h2)+$imcen;
    for ($x=0 ; $x<=$h1; $x=$x+1) {
      $rec=$s*($x-$w2)+$recen;
      $re=$rec;
      $im=$imc;
      $color=1000;
      $re2=$re*$re;
      $im2=$im*$im;
      while( ((($re2+$im2)<1000000) && $color>0)) {
        $im=$re*$im*2+$imc;
        $re=$re2-$im2+$rec;
        $re2=$re*$re;
        $im2=$im*$im;
        $color=$color-1;
      }
      if ( $color==0 ) {
        print "_";
      } else {
        print "#";
      }
    }
    print "<br>";
    flush();
  }
}
mandel2 ( )

Definition at line 86 of file bench.php.

                   {
  $b = " .:,;!/>)|&IH%*#";
  //float r, i, z, Z, t, c, C;
  for ($y=30; printf("\n"), $C = $y*0.1 - 1.5, $y--;){
    for ($x=0; $c = $x*0.04 - 2, $z=0, $Z=0, $x++ < 75;){
      for ($r=$c, $i=$C, $k=0; $t = $z*$z - $Z*$Z + $r, $Z = 2*$z*$Z + $i, $z=$t, $k<5000; $k++)
        if ($z*$z + $Z*$Z > 500000) break;
      echo $b[$k%16];
    }
  }
}
matrix ( n)

Definition at line 293 of file bench.php.

                    {
  $SIZE = 30;
  $m1 = mkmatrix($SIZE, $SIZE);
  $m2 = mkmatrix($SIZE, $SIZE);
  while ($n--) {
    $mm = mmult($SIZE, $SIZE, $m1, $m2);
  }
  print "{$mm[0][0]} {$mm[2][3]} {$mm[3][2]} {$mm[4][4]}\n";
}

Here is the call graph for this function:

Here is the caller graph for this function:

mkmatrix ( rows,
cols 
)

Definition at line 268 of file bench.php.

                                 {
    $count = 1;
    $mx = array();
    for ($i=0; $i<$rows; $i++) {
       for ($j=0; $j<$cols; $j++) {
           $mx[$i][$j] = $count++;
       }
    }
    return($mx);
}

Here is the caller graph for this function:

mmult ( rows,
cols,
m1,
m2 
)

Definition at line 279 of file bench.php.

                                        {
    $m3 = array();
    for ($i=0; $i<$rows; $i++) {
       for ($j=0; $j<$cols; $j++) {
           $x = 0;
           for ($k=0; $k<$cols; $k++) {
              $x += $m1[$i][$k] * $m2[$k][$j];
           }
           $m3[$i][$j] = $x;
       }
    }
    return($m3);
}

Here is the caller graph for this function:

nestedloop ( n)

Definition at line 305 of file bench.php.

                        {
  $x = 0;
  for ($a=0; $a<$n; $a++)
    for ($b=0; $b<$n; $b++)
      for ($c=0; $c<$n; $c++)
        for ($d=0; $d<$n; $d++)
          for ($e=0; $e<$n; $e++)
            for ($f=0; $f<$n; $f++)
             $x++;
  print "$x\n";
}
sieve ( n)

Definition at line 319 of file bench.php.

                   {
  $count = 0;
  while ($n-- > 0) {
    $count = 0;
    $flags = range (0,8192);
    for ($i=2; $i<8193; $i++) {
      if ($flags[$i] > 0) {
        for ($k=$i+$i; $k <= 8192; $k+=$i) {
          $flags[$k] = 0;
        }
        $count++;
      }
    }
  }
  print "Count: $count\n";
}
simple ( )

Definition at line 7 of file bench.php.

                  {
  $a = 0;
  for ($i = 0; $i < 1000000; $i++) 
    $a++;

  $thisisanotherlongname = 0;
  for ($thisisalongname = 0; $thisisalongname < 1000000; $thisisalongname++) 
    $thisisanotherlongname++;
}

Definition at line 19 of file bench.php.

                      {
  for ($i = 0; $i < 1000000; $i++) 
    strlen("hallo");
}

Definition at line 29 of file bench.php.

                       {
  for ($i = 0; $i < 1000000; $i++) 
    hallo("hallo");
}

Here is the call graph for this function:

Definition at line 36 of file bench.php.

                        {
  for ($i = 0; $i < 1000000; $i++) 
    hallo2("hallo");
}

Here is the call graph for this function:

Definition at line 355 of file bench.php.

{
       ob_start();
  return getmicrotime();
}

Here is the call graph for this function:

strcat ( n)

Definition at line 338 of file bench.php.

                    {
  $str = "";
  while ($n-- > 0) {
    $str .= "hello\n";
  }
  $len = strlen($str);
  print "$len\n";
}

Here is the caller graph for this function:

total ( )

Definition at line 375 of file bench.php.

{
  global $total;
  $pad = str_repeat("-", 24);
  echo $pad."\n";
  $num = number_format($total,3);
  $pad = str_repeat(" ", 24-strlen("Total")-strlen($num));
  echo "Total".$pad.$num."\n";
}

Here is the caller graph for this function:


Variable Documentation

$t = end_test($t, "simple")

Definition at line 387 of file bench.php.

$t0 = $t = start_test()

Definition at line 385 of file bench.php.