Skip to content

Instantly share code, notes, and snippets.

@dave1010
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dave1010/f8741f237ac000eb706c to your computer and use it in GitHub Desktop.
Save dave1010/f8741f237ac000eb706c to your computer and use it in GitHub Desktop.
PHP object instantiation benchmark
<?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