Last active
July 13, 2018 08:22
-
-
Save vtr0n/441a75a33bb8cafbc3bd04eeada0e6ce to your computer and use it in GitHub Desktop.
PHP benchmark static function, object function, function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class SomeStaticClass | |
{ | |
public static function doTest($i) { | |
sqrt($i); | |
} | |
} | |
class SomeClass | |
{ | |
public function doTest($i) { | |
sqrt($i); | |
} | |
} | |
function someTest($i){ | |
sqrt($i); | |
} | |
// bench static method | |
$startTime = microtime(true); | |
for ($i = 0; $i< 10*1000*1000; $i++) | |
SomeStaticClass::doTest($i); | |
echo "Static Time: " , (microtime(true)-$startTime) , " ms\n"; | |
// bench object method | |
$startTime = microtime(true); | |
$someObj = new SomeClass(); | |
for ($i = 0; $i< 10*1000*1000; $i++) | |
$someObj->doTest($i); | |
echo "Object Time: " , (microtime(true)-$startTime) , " ms\n"; | |
// bench function | |
$startTime = microtime(true); | |
for ($i = 0; $i< 10*1000*1000; $i++) | |
someTest($i); | |
echo "Function Time: " , (microtime(true)-$startTime) , " ms\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment