simpleudcall(); $t = end_test($t, "simpleudcall"); mandel(); $t = end_test($t, "mandel"); mandel2(); $t = end_test($t, "mandel2"); ackermann(7); $t = end_test($t, "ackermann(7)"); ary(50000); $t = end_test($t, "ary(50000)"); ary2(50000); $t = end_test($t, "ary2(50000)"); ary3(2000); $t = end_test($t, "ary3(2000)"); fibo(30); $t = end_test($t, "fibo(30)"); hash1(50000); $t = end_test($t, "hash1(50000)"); hash2(500); $t = end_test($t, "hash2(500)"); heapsort(20000); $t = end_test($t, "heapsort(20000)"); matrix(20); $t = end_test($t, "matrix(20)"); nestedloop(12); $t = end_test($t, "nestedloop(12)"); sieve(30); $t = end_test($t, "sieve(30)"); strcat(200000); $t = end_test($t, "strcat(200000)"); total($t0, "Total");
function main_function() { for ($i = 0; $i < 100; ++$i) { ackermann(4); ary(50000); ary2(50000); ary3(100); fibo(23); hash1(10000); hash2(200); heapsort(2000); matrix(3); nestedloop(8); sieve(5); strcat(80000); binary_trees(7); fannkuch(6); } }
<?php /* $Id: hash2.php,v 1.1 2004/02/16 14:35:19 tim Exp $ http://www.bagley.org/~doug/shootout/ */ $n = $argc == 2 ? $argv[1] : 1000; hash2($n); function hash2($n) { for ($i = 0; $i < 1000; $i++) { $hash1["foo_{$i}"] = $i; } for ($i = $n; $i > 0; $i--) { foreach ($hash1 as $key => $value) { $hash2[$key] += $value; } } print "{$hash1['foo_1']} {$hash1['foo_9999']} {$hash2['foo_1']} {$hash2['foo_9999']}\n"; }
<?php function hash2($n) { 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"; } hash2(5);
return $t['sec'] + $t['usec'] / 1000000; } function start_test() { ob_start(); return getmicrotime(); } function end_test($start, $name) { 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(); } function total() { 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"; } $t0 = $t = start_test(); hash2(1900); $t = end_test($t, "hash2(500)");
{ $h = 7; $letters = "acdegilmnoprstuw"; for ($i = 0; $i < strlen($s); $i++) { $pos = strpos($letters, $s[$i]); if ($pos === false) { $char = $s[$i]; unset($pos); throw new ErrorException("The character {$char} does not exist in the string {$letters}"); } else { $h = $h * 37 + $pos; } } return $h; } echo hash2("leepadg") . "\n"; function recursive_hash2($s, $j) { $letters = "acdegilmnoprstuw"; if ($j == 0) { return 7; } else { return recursive_hash2($s, --$j) * 37 + strpos($letters, $s[$j]); } } $str = "leepadg"; echo recursive_hash2($str, strlen($str)) . "\n"; function reverse_hash2($number) { $letters = "acdegilmnoprstuw"; $reduced = ($number - $number % 37) / 37;
function main_function() { ackermann(2); ary(500); ary2(500); ary3(5); fibo(13); hash1(100); hash2(20); heapsort(200); matrix(3); nestedloop(3); sieve(1); strcat(80); binary_trees(3); fannkuch(6); }
static function hash2() { Timing::Start("hash2.php"); hash2(1000); Timing::Stop(); }