Skip to content

Instantly share code, notes, and snippets.

@laruence
Created June 27, 2013 16:20
Show Gist options
  • Save laruence/5877870 to your computer and use it in GitHub Desktop.
Save laruence/5877870 to your computer and use it in GitHub Desktop.
test
<?php
interface Foo {
public function foo();
public function foo1($a);
public function foo2($b, $c = NULL);
public function foo3($e, $c = NULL);
public function foo4(array $f);
}
class Bar {
public function foo() {}
public function foo1($a) {}
public function foo2($b, $c = NULL) {}
public function foo3($e, $c = NULL) {}
public function foo4(array $f) {}
}
class Bar1 {
public function foo() {}
public function foo1($a) {}
public function foo2($b, $c = NULL) {}
public function foo3($e, $c = NULL) {}
public function foo4(array $f) {}
}
class Bar2 {
public function foo() {}
public function foo1($a) {}
public function foo2($b, $c = NULL) {}
public function foo3($e, $c = NULL) {}
public function foo4(array $f) {}
}
class Baz implements Foo {
public function foo() {}
public function foo1($a) {}
public function foo2($b, $c = NULL) {}
public function foo3($e, $c = NULL) {}
public function foo4(array $f) {}
}
class Baz1 implements Foo {
public function foo() {}
public function foo1($a) {}
public function foo2($b, $c = NULL) {}
public function foo3($e, $c = NULL) {}
public function foo4(array $f) {}
}
class Baz2 implements Foo {
public function foo() {}
public function foo1($a) {}
public function foo2($b, $c = NULL) {}
public function foo3($e, $c = NULL) {}
public function foo4(array $f) {}
}
function benchmark($func, $times, $arg) {
$s = microtime(true);
for ($i = 0; $i < $times; $i++) {
$func($arg);
}
$e = microtime(true);
return $e - $s;
}
$times = 1000000;
$interface = benchmark(function(Foo $foo) {}, $times, new Baz);
$interface = benchmark(function(Foo $foo) {}, $times, new Baz1);
$interface = benchmark(function(Foo $foo) {}, $times, new Baz2);
echo "Interface in $interface seconds, " . ($interface / $times) . " seconds per run\n";
$structural = benchmark(function(<Foo> $foo) {}, $times, new Bar);
$structural = benchmark(function(<Foo> $foo) {}, $times, new Bar1);
$structural = benchmark(function(<Foo> $foo) {}, $times, new Bar2);
echo "Structural in $structural seconds, " . ($structural / $times) . " seconds per run\n";
$native = benchmark(function($foo) {}, $times, new Bar);
$native = benchmark(function($foo) {}, $times, new Bar1);
$native = benchmark(function($foo) {}, $times, new Bar2);
echo "Native in $native seconds, " . ($native / $times) . " seconds per run\n";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment