Created
June 27, 2013 16:20
-
-
Save laruence/5877870 to your computer and use it in GitHub Desktop.
test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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