Skip to content

Instantly share code, notes, and snippets.

@ircmaxell
Forked from laruence/gist:5877870
Last active December 19, 2015 01:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ircmaxell/5878060 to your computer and use it in GitHub Desktop.
Save ircmaxell/5878060 to your computer and use it in GitHub Desktop.
<?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 = 0;
$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 * 3)) . " seconds per run\n";
$structural = 0;
$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 * 3)) . " seconds per run\n";
$native = 0;
$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 * 3)) . " seconds per run\n";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment