<?php
class Foo {
public function do_foo($one, $two, $three) {}
}
class Bar {
private $methods;
public function __construct() {
$this->methods['do_foo'] = function($one, $two, $three) {};
}
public function __call($name, $args) {
call_user_func_array($this->methods[$name], $args);
}
}
$rounds = 100000;
$tests = [new Foo(), new Bar()];
foreach ($tests as $test) {
echo get_class($test), "\n";
$time = -microtime(true);
for ($i = 0; $i < $rounds; ++$i) {
$test->do_foo(1, 2, 3);
}
$time += microtime(true);
echo "$time msecs\n";
}
preferences:
30.94 ms | 402 KiB | 5 Q