__call overhead

Submitted by tomek on Sun, 05/08/2011 - 13:45

f2 is slower than f1 by 249.18% (2.5 times slower)

Full source code as executed.
define('LOOP',10000000);
 
class ClassA {
  public function normal() {
  }
 
  public function __call($name,$args) {
  }
}
function f1() {
  $a = new ClassA();
  for($i=0; $i<LOOP; ++$i) {
    $a->normal();
  }
}
 
function f2() {
  $a = new ClassA();
  for($i=0; $i<LOOP; ++$i) {
    $a->magic();  
  }
}
 
$start = microtime(true);
f1();
$stop = microtime(true);
$time1 = $stop - $start;
 
$start = microtime(true);
f2();
$stop = microtime(true);
$time2 = $stop - $start;
 
echo $time1 . "\t";
echo $time2 . "\n";
Test results
comparisontime1time2php_version
184.31%9008158256107095.3.5-1ubuntu7.2
344.98%7771667345825205.3.3-7
302.5%14189037571103375.3.5-1ubuntu7.2
338.7%7676243336759155.3.3-7+squeeze1
203.39%12135363681758php-5.3.6-phpbrew_compiled
197.61%11786013507621php-5.3.7-phpbrew_compiled
190.11%12111043513550php-5.3.8-phpbrew_compiled
187.62%12106493482080php-5.3.9-phpbrew_compiled
179.2%12185733402201php-5.3.10-phpbrew_compiled
196.39%12288723642300php-5.3.11-phpbrew_compiled
196.1%12284143637280php-5.3.12-phpbrew_compiled
195.92%12297563639075php-5.3.13-phpbrew_compiled
187.89%12009113457355php-5.3.14-phpbrew_compiled
162.04%14169823713021php-5.3.15-phpbrew_compiled
184.51%12517293561350php-5.3.16-phpbrew_compiled
183.39%12200693457548php-5.3.17-phpbrew_compiled
203.43%12077353664669php-5.3.18-phpbrew_compiled
113.06%16274303467352php-5.3.19-phpbrew_compiled
343.35%6514742888324php-5.4.0-phpbrew_compiled
286.96%7952253077196php-5.4.1-phpbrew_compiled
355.38%7095953231379php-5.4.2-phpbrew_compiled
286.46%7984463085713php-5.4.3-phpbrew_compiled
343.87%6473272873274php-5.4.4-phpbrew_compiled
340.19%6542562879947php-5.4.5-phpbrew_compiled
349.09%6489302914304php-5.4.6-phpbrew_compiled
348.74%6545312937152php-5.4.7-phpbrew_compiled
361.66%6555963026607php-5.4.8-phpbrew_compiled
210.08%9861663057916php-5.4.9-phpbrew_compiled
50%
updown
50%