Project

General

Profile

Bug #23104 » 15020_testInt_test_v1.php

Administrator Admin, 2010-07-06 23:42

 
<?php

$times = 30000;

function testInt ($var) {
return !strcmp($var, intval($var));
}

function testIntVariant1 ($var) {
return is_int($var);
}

function test ($function, $a, $b) {
global $times;
$time_start = microtime(TRUE);
for ($i = 0; $i < $times; $i++) {
$function($a, $b);
}
return (microtime(TRUE) - $time_start);
}

$testcases = array (
'int' => array (
'32425',
),
'string' => array (
'the quick brown fox'
),
'NULL' => array (
NULL
),
'array str' => array (
array ('a', 'b'),
),
);

foreach ($testcases as $name => $parameters) {
echo "\n$name";

$baseTime = test ('testInt', $parameters[0], $parameters[1]);
echo "\noriginal : " . sprintf("%.3f", $baseTime);
$time = test ('testIntVariant1', $parameters[0], $parameters[1]);
echo "\nvariant1 : " . sprintf("%.3f", $time) . ' gain ' . number_format((($baseTime/$time)*100) - 100, 1) . ' %';

echo "\n";
}

?>
(9-9/10)