Skip to content

Instantly share code, notes, and snippets.

@asgrim
Created October 11, 2015 19:12
Show Gist options
  • Save asgrim/6d15b30cbba2b8b6091d to your computer and use it in GitHub Desktop.
Save asgrim/6d15b30cbba2b8b6091d to your computer and use it in GitHub Desktop.
<?php
require "vendor/autoload.php";
class Foo {
public function bar() {}
}
$c = 1000;
echo "using method_exists... ";
$t = microtime(true);
for($i = 0; $i < $c; $i++) {
method_exists('Foo', 'bar');
}
echo (microtime(true) - $t) . " seconds.\n";
echo "using core reflection... ";
$t = microtime(true);
for($i = 0; $i < $c; $i++) {
$r = new ReflectionClass('Foo');
$r->hasMethod('bar');
}
echo (microtime(true) - $t) . " seconds.\n";
echo "using better reflection... ";
$t = microtime(true);
for($i = 0; $i < $c; $i++) {
$br = \BetterReflection\Reflection\ReflectionClass::createFromName('Foo');
$br->hasMethod('bar');
}
echo (microtime(true) - $t) . " seconds.\n";
using method_exists... 0.0006260871887207 seconds.
using core reflection... 0.0013439655303955 seconds.
using better reflection... 7.447105884552 seconds.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment