Last active
August 29, 2015 14:13
-
-
Save dave1010/f8741f237ac000eb706c to your computer and use it in GitHub Desktop.
PHP object instantiation benchmark
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 Foo { | |
public function __construct($i) | |
{ | |
$this->bar = $i; | |
} | |
} | |
$start = microtime(true); | |
$count = 1000000; | |
for ($i = 0; $i < $count; $i++) { | |
new Foo($i); | |
} | |
$diff = microtime(true) - $start; | |
$time = $diff / $count; | |
echo $time . "s\n"; | |
echo $time*1000 . "ms\n"; | |
echo $time*1000000 . "ns\n"; | |
// Output from local machine, with xdebug running | |
// 7.3847484588623E-7s | |
// 0.00073847484588623ms | |
// 0.73847484588623ns | |
// Output from http://phpfiddle.org | |
// 2.8995680809E-7s | |
// 0.00028995680809ms | |
// 0.28995680809ns |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment