Skip to content

Instantly share code, notes, and snippets.

@vojtabiberle
Created October 23, 2015 16:31
Show Gist options
  • Save vojtabiberle/4e303e3d5ee6d39459a7 to your computer and use it in GitHub Desktop.
Save vojtabiberle/4e303e3d5ee6d39459a7 to your computer and use it in GitHub Desktop.
<?php
class Foo {
public $str1 = 'hello';
protected $str2 = 'world';
private $str3 = 'meh';
public function __construct()
{
// just for fun
}
public function getWorld()
{
return $this->str2;
}
public function setState($value)
{
$this->str3 = $value;
}
public static function moo()
{
echo 'moo';
}
}
$limit = 10000000;
$start = microtime(true);
for($i = 0; $i < $limit; $i++) {
$reflected = new \ReflectionClass('Foo');
unset($reflected);
}
$reflected1 = microtime(true) - $start;
$class = new Foo();
$start = microtime(true);
for($i = 0; $i < $limit; $i++) {
$reflected = new \ReflectionClass($class);
unset($reflected);
}
$reflected2 = microtime(true) - $start;
$start = microtime(true);
for($i = 0; $i < $limit; $i++) {
$arr = [1,2,3];
unset($arr);
}
$array = microtime(true) - $start;
echo 'Reflection with string: ' . $reflected1 . PHP_EOL;
echo 'Reflection with object: ' . $reflected2 . PHP_EOL;
echo 'Array creation: ' . $array . PHP_EOL;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment