Closed simonschaufi closed 2 years ago
Hi @simonschaufi,
Can you please explain what issue this pull requests fixes?
This is a micro optimization because static functions are slightly faster, which I confirmed myself:
<?php
class SomeClass
{
public function doTest($i)
{
}
public static function doStaticTest($i)
{
}
}
$someObj = new SomeClass();
// bench static method
$starttime = microtime(true);
for ($i = 0; $i< 100*1000*1000; $i++) {
SomeClass::doStaticTest($i);
}
echo 'Static Time: ' , (microtime(true)-$starttime) , " ms\n";
// bench object method
$starttime = microtime(true);
for ($i = 0; $i < 100*1000*1000; $i++) {
$someObj->doTest($i);
}
echo 'Object Time: ' , (microtime(true)-$starttime) , " ms\n";
// bench non static closure
$starttime = microtime(true);
$myList = [1];
for ($i = 0; $i < 10*1000*1000; $i++) {
array_map(function ($i) {
return $i;
}, $myList);
}
echo 'Non static closure Time: ' , (microtime(true)-$starttime) , " ms\n";
// bench static closure
$starttime = microtime(true);
for ($i = 0; $i < 10*1000*1000; $i++) {
array_map(static function ($i) {
return $i;
}, $myList);
}
echo 'Static closure Time: ' , (microtime(true)-$starttime) , " ms\n";
Static Time: 1.269611120224 ms
Object Time: 1.7090179920197 ms
Non static closure Time: 1.4039039611816 ms
Static closure Time: 1.367977142334 ms
Unfortunately you missed some fixes.
thanx :partying_face:
Hi @simonschaufi,
Can you please explain what issue this pull requests fixes?