类的定义如下:
复制代码 代码如下:
class test
{
public static function a(){}
public function b(){}
}
$obj = new test;
复制代码 代码如下:
$obj = new test;
$test_times = 100;
$times = 10000;
$effi1 = array();
$effi2 = array();
while ($test_times-- > 0)
{
$time1 = microtime(true);
for($i=0; $i{
test::a();
}
$time2 = microtime(true);
for($i=0; $i{
$obj->a();
}
$time3 = microtime(true);
for($i=0; $i{
$obj->b();
}
$time4 = microtime(true);
$effi1[] = ($time3 - $time2) / ($time2 - $time1);
$effi2[] = ($time4 - $time3) / ($time3 - $time2);
}
echo avg($effi1),"\n",avg($effi2);
复制代码 代码如下:
function avg($arr)
{
$result = 0;
foreach ($arr as $val)
{
$result += $val;
}
$result /= count($arr);
return $result;
}
复制代码 代码如下:
PHP 5.2.14
view sourceprint?1 0.76490628848091
2 1.0699484376399
view sourceprint?1 PHP 5.3
view sourceprint?1 0.56919482299058
1.1016495598611