<?php
/*
##########################################################################
# PHP Benchmark Performance Script #
# <A9> 2010 Code24 BV #
# #
# Author : Alessandro Torrisi #
# Company : Code24 BV, The Netherlands #
# Date : July 31, 2010 #
# version : 1.0 #
# License : Creative Commons CC-BY license #
# Website : http://www.php-benchmark-script.com #
# #
##########################################################################
*/
set_time_limit(0);
function get_microtime()
{
$time = microtime(true);
if (is_string($time)) {
list($f, $i) = explode(" ", $time);
$time = intval($i) + floatval($f);
}
return $time;
}
function test_Math($count = 14000) {
$time_start = get_microtime();
$mathFunctions = array("abs", "acos", "asin", "atan", "bindec", "floor", "exp", "sin", "tan", "pi", "is_finite", "is_nan", "sqrt");
foreach ($mathFunctions as $key => $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(get_microtime() - $time_start, 3);
}
function test_StringManipulation($count = 13000) {
$time_start = get_microtime();
$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(get_microtime() - $time_start, 3);
}
function test_Loops($count = 1900000) {
$time_start = get_microtime();
for($i = 0; $i < $count; ++$i);
$i = 0; while($i++ < $count);
return number_format(get_microtime() - $time_start, 3);
}
function test_IfElse($count = 900000) {
$time_start = get_microtime();
for ($i=0; $i < $count; $i++) {
if ($i == -1) {
} elseif ($i == -2) {
} else if ($i == -3) {
}
}
return number_format(get_microtime() - $time_start, 3);
}
$total = 0;
$functions = get_defined_functions();
$line = str_pad("-",38,"-");
echo "<pre>\n$line\n|".str_pad("PHP BENCHMARK SCRIPT",36," ",STR_PAD_BOTH)."|\n$line\nStart : ".date("Y-m-d H:i:s")."\nServer : ".php_uname()."\nPHP version : ".PHP_VERSION."\nPlatform : ".PHP_OS. "\n$line\n";
foreach ($functions['user'] as $user) {
if (preg_match('/^test_/', $user)) {
$result = $user();
$total += $result;
echo str_pad($user, 25) . " : " . $result ." sec.\n";
}
}
echo str_pad("-", 38, "-") . "\n" . str_pad("Total time:", 25) . " : " . $total ." sec.\n</pre>\n";
preferences:
33.55 ms | 402 KiB | 5 Q