The Apache Haus Forum

Advanced search  

News:

Welcome to Apache Haus Distribution Forum

Pages: [1]   Go Down

Author Topic: PHP OOP Static vs. Dynamic  (Read 6488 times)

mario

  • Administrator
  • Member Elite
  • *****
  • Offline Offline
  • Posts: 580
PHP OOP Static vs. Dynamic
« on: December 17, 2008, 11:32:14 PM »

Code: [Select]
<?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!   ;)
Logged
Pages: [1]   Go Up
 

Sitemap 1 2 3 4 5 6 7 8 9 10 11 12 13