$function) { if (!function_exists($function)) unset($mathFunctions[$key]); } for ($i=0; $i < $count; $i++) { foreach ($mathFunctions as $function) { $r = call_user_func_array($function, array($i)); } } return number_format(microtime(true) - $time_start, 3); } function test_StringManipulation($count = 100000) { $time_start = microtime(true); $stringFunctions = array("addslashes", "chunk_split", "metaphone", "strip_tags", "md5", "sha1", "strtoupper", "strtolower", "strrev", "strlen", "soundex", "ord"); foreach ($stringFunctions as $key => $function) { if (!function_exists($function)) unset($stringFunctions[$key]); } $string = "the quick brown fox jumps over the lazy dog"; for ($i=0; $i < $count; $i++) { foreach ($stringFunctions as $function) { $r = call_user_func_array($function, array($string)); } } return number_format(microtime(true) - $time_start, 3); } function test_Loops($count = 10000000) { $time_start = microtime(true); for($i = 0; $i < $count; ++$i); $i = 0; while($i < $count) ++$i; return number_format(microtime(true) - $time_start, 3); } function test_IfElse($count = 10000000) { $time_start = microtime(true); for ($i=0; $i < $count; $i++) { if ($i == -1) { } elseif ($i == -2) { } else if ($i == -3) { } } return number_format(microtime(true) - $time_start, 3); } $numtimes=$_GET["numtimes"]; if ($numtimes <=0) { $numtimes = 1; } if ($numtimes>10) { $numtimes =10; } $functions = get_defined_functions(); $line = str_pad("-",56,"-"); echo "
\n$line\n|".str_pad("PHP BENCHMARK SCRIPT",54," ",STR_PAD_BOTH)."|\n$line\nStart : ".date("Y-m-d H:i:s")."\nServer : {$_SERVER['SERVER_NAME']}@{$_SERVER['SERVER_ADDR']}\nPHP version : ".PHP_VERSION."\nPlatform : ".PHP_OS. "\n$line\n";
	for ($xrun=1;$xrun<=$numtimes;$xrun++) {
		$total = 0;
		foreach ($functions['user'] as $user) {
			if (preg_match('/^test_/', $user)) {
				$total += $result = $user();
				echo "Test #".$xrun." ".str_pad($user, 33) . " : " . sprintf("%5.2f",$result) ." seconds\n";
			}
		}
		$totaltime = sprintf("%5.2f",$totaltime + $total);
		if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
			$serverphpload = 0;
		}  else {
			$serverphpload = sys_getloadavg();
			$serverload = sprintf("%5.2f",$serverphpload[0]);
			$tserverload=sprintf("%5.2f",$tserverload+$serverload);
			$results[]=sprintf("%5.2f",$total);	
			printf("
Server time : %5.02f seconds",$total); printf("
Server load (now) : %5.02f",$serverload); } echo "
".$line."\n"; echo str_repeat(' ',1024*64); // for flush to work in IE... echo "\n"; ob_flush(); flush(); } $besttime = min($results); $worsttime= max($results); if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { $serverphpload = 0; } else { $serverphpload = sys_getloadavg(); } printf("
Total time : %5.02f seconds",$totaltime); if ($numtimes>1) { $avgload = sprintf("%5.2f",$tserverload/$numtimes); printf("
Average per test : %5.02f seconds",$totaltime/$numtimes); printf("
Best time : %5.02f seconds",$besttime); printf("
Worst time : %5.02f seconds
",$worsttime); printf("
Total server load : %5.02f",$tserverload); printf("
Average server load : %5.02f",$avgload); } printf("
Average load last 5 minutes : %5.02f",$serverphpload[1]); printf("
Average load last 15 minutes : %5.02f",$serverphpload[2]); $memorylimit = ini_get("memory_limit"); printf("
PHP memory limit : %5.00f Mbyte
",$memorylimit); echo "
"; echo "You can download this script here and test it on your own server (requires PHP 5)."; echo "

If you want to test your own server you can download it in the link above, rename it to bench.php and upload it to you own web server. The script requires PHP 5 to run.\n\n"; echo "

Remote address: ".$_SERVER['REMOTE_ADDR']; ?>