静态方法比非静态方法快吗?
编辑::哦,我忘了
class Test1{
public static function test(){
for($i=0; $i<=1000; $i++)
$j += $i;
}
}
class Test2{
public function test() {
for ($i=0; $i<=1000; $i++){
$j += $i;
}
}
}
对于此算法
$time_start = microtime();
$test1 = new Test2();
for($i=0; $i<=100;$i++)
$test1->test();
$time_end = microtime();
$time1 = $time_end - $time_start;
$time_start = microtime();
for($i=0; $i<=100;$i++)
Test1::test();
$time_end = microtime();
$time2 = $time_end - $time_start;
$time = $time1 - $time2;
echo "Difference: $time";
我有结果
Difference: 0.007561
这些天,我试图使我的方法尽可能静态。但这是真的吗, ..至少对于 php