PHP OOP Static vs. Dynamic

Started by mario, December 17, 2008, 11:32:14 PM

Previous topic - Next topic

mario


<?php
class bench {
    public function 
a() { return 1; }
    public static function 
b() { return 1; }
}
$s microtime(1);
for (
$i 0$i 100000$i++) bench::a();
$e microtime(1);
echo 
"Dynamic Static Method: ".($e $s)."\n";
$s microtime(1);
for (
$i 0$i 100000$i++) bench::b();
$e microtime(1);
echo 
"Declared Static Method: ".($e $s)."\n";
$s microtime(1);
$bench = new bench;
for (
$i 0$i 100000$i++) $bench->a();
$e microtime(1);
echo 
"Dynamic called Method: ".($e $s)."\n";
?>


Result:
Dynamic Static Method: 0.27507710456848
Declared Static Method: 0.11795783042908
Dynamic called Method: 0.10040712356567


As you can see a static declared static called method is faster than a dynamic static called method, but the full dynamic is faster!   ;)