Created
September 5, 2014 16:02
-
-
Save drsnyder/85b3a4d3381ea6232136 to your computer and use it in GitHub Desktop.
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 FooBar { } | |
$fooBar = new FooBar(); | |
$iterations = 1e6; | |
$assignment = false; | |
$start = microtime(true); | |
for ($i=0; $i<$iterations; $i++) { | |
if ($fooBar instanceof FooBar) { | |
$assignment = true; | |
} | |
} | |
$instanceOnly = microtime(true) - $start; | |
fprintf(STDERR, "instance only: %2.2f\n", $instanceOnly); | |
$assignment = false; | |
$start = microtime(true); | |
for ($i=0; $i<$iterations; $i++) { | |
assert($fooBar instanceof FooBar); | |
$assignment = true; | |
} | |
$assert = microtime(true) - $start; | |
fprintf(STDERR, "assert: %2.2f\n", $assert); | |
fprintf(STDERR, "assert adds %2.6f ms overhead per invocation\n", ( ($assert - $instanceOnly) / $iterations ) * 1000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment