Skip to content

Instantly share code, notes, and snippets.

@asgrim

asgrim/bench.php

Created Oct 11, 2015
Embed
What would you like to do?
<?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