gnopaste

Sorry for this ugly message. We are searching for some translators.
Please send me an eMail or jabber: t4c@im.digital-bit.ch
Got: de, en, pl, ro, lu, ru, es - Need: everything else

Name
CVB
Scriptlanguage
PHP
Tabwidth
4
Date
07/23/2009 03:15:03 pm
IP
195.243.129.130

PHP-Benchmark
http://svn.php.net/viewvc/php/php-src/branches/PHP_5_3/Zend/bench.php?view=markup&pathrev=284034

  1. <?php
  2.  
  3. if (function_exists("date_default_timezone_set")) {
  4.     date_default_timezone_set("UTC");
  5. }
  6.  
  7. date_default_timezone_set('UTC');
  8. function simple() {
  9.   $a = 0;
  10.   for ($i = 0; $i < 1000000; $i++)
  11.     $a++;
  12.  
  13.   $thisisanotherlongname = 0;
  14.   for ($thisisalongname = 0; $thisisalongname < 1000000; $thisisalongname++)
  15.     $thisisanotherlongname++;
  16. }
  17.  
  18. /****/
  19.  
  20. function simplecall() {
  21.   for ($i = 0; $i < 1000000; $i++)
  22.     strlen("hallo");
  23. }
  24.  
  25. /****/
  26.  
  27. function hallo($a) {
  28. }
  29.  
  30. function simpleucall() {
  31.   for ($i = 0; $i < 1000000; $i++)
  32.     hallo("hallo");
  33. }
  34.  
  35. /****/
  36.  
  37. function simpleudcall() {
  38.   for ($i = 0; $i < 1000000; $i++)
  39.     hallo2("hallo");
  40. }
  41.  
  42. function hallo2($a) {
  43. }
  44.  
  45. /****/
  46.  
  47. function mandel() {
  48.   $w1=50;
  49.   $h1=150;
  50.   $recen=-.45;
  51.   $imcen=0.0;
  52.   $r=0.7;
  53.   $s=0;  $rec=0;  $imc=0;  $re=0;  $im=0;  $re2=0;  $im2=0;
  54.   $x=0;  $y=0;  $w2=0;  $h2=0;  $color=0;
  55.   $s=2*$r/$w1;
  56.   $w2=40;
  57.   $h2=12;
  58.   for ($y=0 ; $y<=$w1; $y=$y+1) {
  59.     $imc=$s*($y-$h2)+$imcen;
  60.     for ($x=0 ; $x<=$h1; $x=$x+1) {
  61.       $rec=$s*($x-$w2)+$recen;
  62.       $re=$rec;
  63.       $im=$imc;
  64.       $color=1000;
  65.       $re2=$re*$re;
  66.       $im2=$im*$im;
  67.       while( ((($re2+$im2)<1000000) && $color>0)) {
  68.         $im=$re*$im*2+$imc;
  69.         $re=$re2-$im2+$rec;
  70.         $re2=$re*$re;
  71.         $im2=$im*$im;
  72.         $color=$color-1;
  73.       }
  74.       if ( $color==0 ) {
  75.         print "_";
  76.       } else {
  77.         print "#";
  78.       }
  79.     }
  80.     print "<br>";
  81.     flush();
  82.   }
  83. }
  84.  
  85. /****/
  86.  
  87. function mandel2() {
  88.   $b = " .:,;!/>)|&IH%*#";
  89.   //float r, i, z, Z, t, c, C;
  90.   for ($y=30; printf("\n"), $C = $y*0.1 - 1.5, $y--;){
  91.     for ($x=0; $c = $x*0.04 - 2, $z=0, $Z=0, $x++ < 75;){
  92.       for ($r=$c, $i=$C, $k=0; $t = $z*$z - $Z*$Z + $r, $Z = 2*$z*$Z + $i, $z=$t, $k<5000; $k++)
  93.         if ($z*$z + $Z*$Z > 500000) break;
  94.       echo $b[$k%16];
  95.     }
  96.   }
  97. }
  98.  
  99. /****/
  100.  
  101. function Ack($m, $n){
  102.   if($m == 0) return $n+1;
  103.   if($n == 0) return Ack($m-1, 1);
  104.   return Ack($m - 1, Ack($m, ($n - 1)));
  105. }
  106.  
  107. function ackermann($n) {
  108.   $r = Ack(3,$n);
  109.   print "Ack(3,$n): $r\n";
  110. }
  111.  
  112. /****/
  113.  
  114. function ary($n) {
  115.   for ($i=0; $i<$n; $i++) {
  116.     $X[$i] = $i;
  117.   }
  118.   for ($i=$n-1; $i>=0; $i--) {
  119.     $Y[$i] = $X[$i];
  120.   }
  121.   $last = $n-1;
  122.   print "$Y[$last]\n";
  123. }
  124.  
  125. /****/
  126.  
  127. function ary2($n) {
  128.   for ($i=0; $i<$n;) {
  129.     $X[$i] = $i; ++$i;
  130.     $X[$i] = $i; ++$i;
  131.     $X[$i] = $i; ++$i;
  132.     $X[$i] = $i; ++$i;
  133.     $X[$i] = $i; ++$i;
  134.  
  135.     $X[$i] = $i; ++$i;
  136.     $X[$i] = $i; ++$i;
  137.     $X[$i] = $i; ++$i;
  138.     $X[$i] = $i; ++$i;
  139.     $X[$i] = $i; ++$i;
  140.   }
  141.   for ($i=$n-1; $i>=0;) {
  142.     $Y[$i] = $X[$i]; --$i;
  143.     $Y[$i] = $X[$i]; --$i;
  144.     $Y[$i] = $X[$i]; --$i;
  145.     $Y[$i] = $X[$i]; --$i;
  146.     $Y[$i] = $X[$i]; --$i;
  147.  
  148.     $Y[$i] = $X[$i]; --$i;
  149.     $Y[$i] = $X[$i]; --$i;
  150.     $Y[$i] = $X[$i]; --$i;
  151.     $Y[$i] = $X[$i]; --$i;
  152.     $Y[$i] = $X[$i]; --$i;
  153.   }
  154.   $last = $n-1;
  155.   print "$Y[$last]\n";
  156. }
  157.  
  158. /****/
  159.  
  160. function ary3($n) {
  161.   for ($i=0; $i<$n; $i++) {
  162.     $X[$i] = $i + 1;
  163.     $Y[$i] = 0;
  164.   }
  165.   for ($k=0; $k<1000; $k++) {
  166.     for ($i=$n-1; $i>=0; $i--) {
  167.       $Y[$i] += $X[$i];
  168.     }
  169.   }
  170.   $last = $n-1;
  171.   print "$Y[0] $Y[$last]\n";
  172. }
  173.  
  174. /****/
  175.  
  176. function fibo_r($n){
  177.     return(($n < 2) ? 1 : fibo_r($n - 2) + fibo_r($n - 1));
  178. }
  179.  
  180. function fibo($n) {
  181.   $r = fibo_r($n);
  182.   print "$r\n";
  183. }
  184.  
  185. /****/
  186.  
  187. function hash1($n) {
  188.   for ($i = 1; $i <= $n; $i++) {
  189.     $X[dechex($i)] = $i;
  190.   }
  191.   $c = 0;
  192.   for ($i = $n; $i > 0; $i--) {
  193.     if ($X[dechex($i)]) { $c++; }
  194.   }
  195.   print "$c\n";
  196. }
  197.  
  198. /****/
  199.  
  200. function hash2($n) {
  201.   for ($i = 0; $i < $n; $i++) {
  202.     $hash1["foo_$i"] = $i;
  203.     $hash2["foo_$i"] = 0;
  204.   }
  205.   for ($i = $n; $i > 0; $i--) {
  206.     foreach($hash1 as $key => $value) $hash2[$key] += $value;
  207.   }
  208.   $first = "foo_0";
  209.   $last  = "foo_".($n-1);
  210.   print "$hash1[$first] $hash1[$last] $hash2[$first] $hash2[$last]\n";
  211. }
  212.  
  213. /****/
  214.  
  215. function gen_random ($n) {
  216.     global $LAST;
  217.     return( ($n * ($LAST = ($LAST * IA + IC) % IM)) / IM );
  218. }
  219.  
  220. function heapsort_r($n, &$ra) {
  221.     $l = ($n >> 1) + 1;
  222.     $ir = $n;
  223.  
  224.     while (1) {
  225.     if ($l > 1) {
  226.         $rra = $ra[--$l];
  227.     } else {
  228.         $rra = $ra[$ir];
  229.         $ra[$ir] = $ra[1];
  230.         if (--$ir == 1) {
  231.         $ra[1] = $rra;
  232.         return;
  233.         }
  234.     }
  235.     $i = $l;
  236.     $j = $l << 1;
  237.     while ($j <= $ir) {
  238.         if (($j < $ir) && ($ra[$j] < $ra[$j+1])) {
  239.         $j++;
  240.         }
  241.         if ($rra < $ra[$j]) {
  242.         $ra[$i] = $ra[$j];
  243.         $j += ($i = $j);
  244.         } else {
  245.         $j = $ir + 1;
  246.         }
  247.     }
  248.     $ra[$i] = $rra;
  249.     }
  250. }
  251.  
  252. function heapsort($N) {
  253.   global $LAST;
  254.  
  255.   define("IM", 139968);
  256.   define("IA", 3877);
  257.   define("IC", 29573);
  258.  
  259.   $LAST = 42;
  260.   for ($i=1; $i<=$N; $i++) {
  261.     $ary[$i] = gen_random(1);
  262.   }
  263.   heapsort_r($N, $ary);
  264.   printf("%.10f\n", $ary[$N]);
  265. }
  266.  
  267. /****/
  268.  
  269. function mkmatrix ($rows, $cols) {
  270.     $count = 1;
  271.     $mx = array();
  272.     for ($i=0; $i<$rows; $i++) {
  273.     for ($j=0; $j<$cols; $j++) {
  274.         $mx[$i][$j] = $count++;
  275.     }
  276.     }
  277.     return($mx);
  278. }
  279.  
  280. function mmult ($rows, $cols, $m1, $m2) {
  281.     $m3 = array();
  282.     for ($i=0; $i<$rows; $i++) {
  283.     for ($j=0; $j<$cols; $j++) {
  284.         $x = 0;
  285.         for ($k=0; $k<$cols; $k++) {
  286.         $x += $m1[$i][$k] * $m2[$k][$j];
  287.         }
  288.         $m3[$i][$j] = $x;
  289.     }
  290.     }
  291.     return($m3);
  292. }
  293.  
  294. function matrix($n) {
  295.   $SIZE = 30;
  296.   $m1 = mkmatrix($SIZE, $SIZE);
  297.   $m2 = mkmatrix($SIZE, $SIZE);
  298.   while ($n--) {
  299.     $mm = mmult($SIZE, $SIZE, $m1, $m2);
  300.   }
  301.   print "{$mm[0][0]} {$mm[2][3]} {$mm[3][2]} {$mm[4][4]}\n";
  302. }
  303.  
  304. /****/
  305.  
  306. function nestedloop($n) {
  307.   $x = 0;
  308.   for ($a=0; $a<$n; $a++)
  309.     for ($b=0; $b<$n; $b++)
  310.       for ($c=0; $c<$n; $c++)
  311.         for ($d=0; $d<$n; $d++)
  312.           for ($e=0; $e<$n; $e++)
  313.             for ($f=0; $f<$n; $f++)
  314.             $x++;
  315.   print "$x\n";
  316. }
  317.  
  318. /****/
  319.  
  320. function sieve($n) {
  321.   $count = 0;
  322.   while ($n-- > 0) {
  323.     $count = 0;
  324.     $flags = range (0,8192);
  325.     for ($i=2; $i<8193; $i++) {
  326.       if ($flags[$i] > 0) {
  327.         for ($k=$i+$i; $k <= 8192; $k+=$i) {
  328.           $flags[$k] = 0;
  329.         }
  330.         $count++;
  331.       }
  332.     }
  333.   }
  334.   print "Count: $count\n";
  335. }
  336.  
  337. /****/
  338.  
  339. function strcat($n) {
  340.   $str = "";
  341.   while ($n-- > 0) {
  342.     $str .= "hello\n";
  343.   }
  344.   $len = strlen($str);
  345.   print "$len\n";
  346. }
  347.  
  348. /*****/
  349.  
  350. function getmicrotime()
  351. {
  352.   $t = gettimeofday();
  353.   return ($t['sec'] + $t['usec'] / 1000000);
  354. }
  355.  
  356. function start_test()
  357. {
  358.     ob_start();
  359.   return getmicrotime();
  360. }
  361.  
  362. function end_test($start, $name)
  363. {
  364.   global $total;
  365.   $end = getmicrotime();
  366.   ob_end_clean();
  367.   $total += $end-$start;
  368.   $num = number_format($end-$start,3);
  369.   $pad = str_repeat(" ", 24-strlen($name)-strlen($num));
  370.  
  371.   echo $name.$pad.$num."\n";
  372.     ob_start();
  373.   return getmicrotime();
  374. }
  375.  
  376. function total()
  377. {
  378.   global $total;
  379.   $pad = str_repeat("-", 24);
  380.   echo $pad."\n";
  381.   $num = number_format($total,3);
  382.   $pad = str_repeat(" ", 24-strlen("Total")-strlen($num));
  383.   echo "Total".$pad.$num."\n";
  384. }
  385.  
  386. $t0 = $t = start_test();
  387. simple();
  388. $t = end_test($t, "simple");
  389. simplecall();
  390. $t = end_test($t, "simplecall");
  391. simpleucall();
  392. $t = end_test($t, "simpleucall");
  393. simpleudcall();
  394. $t = end_test($t, "simpleudcall");
  395. mandel();
  396. $t = end_test($t, "mandel");
  397. mandel2();
  398. $t = end_test($t, "mandel2");
  399. ackermann(7);
  400. $t = end_test($t, "ackermann(7)");
  401. ary(50000);
  402. $t = end_test($t, "ary(50000)");
  403. ary2(50000);
  404. $t = end_test($t, "ary2(50000)");
  405. ary3(2000);
  406. $t = end_test($t, "ary3(2000)");
  407. fibo(30);
  408. $t = end_test($t, "fibo(30)");
  409. hash1(50000);
  410. $t = end_test($t, "hash1(50000)");
  411. hash2(500);
  412. $t = end_test($t, "hash2(500)");
  413. heapsort(20000);
  414. $t = end_test($t, "heapsort(20000)");
  415. matrix(20);
  416. $t = end_test($t, "matrix(20)");
  417. nestedloop(12);
  418. $t = end_test($t, "nestedloop(12)");
  419. sieve(30);
  420. $t = end_test($t, "sieve(30)");
  421. strcat(200000);
  422. $t = end_test($t, "strcat(200000)");
  423. total($t0, "Total");
  424.  
  425. ?>
submitter » gnopaster | imprint « imprint     
» Terms of use «
» digital bit dot ch - t4c's new home «