-
-
Save krakjoe/cef6452281624bdf1b46788f52a01521 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 Foo { | |
private int $property; | |
public function __construct() { | |
$this->reflector = new ReflectionProperty($this, "property"); | |
$this->reflector->setAccessible(true); | |
} | |
public function test() { | |
return is_initialized($this, "property"); | |
} | |
public function testReflection() { | |
return $this->reflector->isInitialized($this); | |
} | |
} | |
$foo = new Foo; | |
$iterations = 1000000; | |
$start = microtime(true); | |
for ($count = 0; $count < $iterations; $count++) | |
$foo->test(); | |
printf("is_initialized: %.5f seconds\n", microtime(true)-$start); | |
$start = microtime(true); | |
for ($count = 0; $count < $iterations; $count++) | |
$foo->testReflection(); | |
printf("reflection: %.5f seconds\n", microtime(true)-$start); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment