is_a / instanceof

Submitted by arney on Fri, 01/04/2013 - 22:56

f1 is slower than f2 by 0%

Full source code as executed.
/* How many times the code under test should run in each function */
define('LOOP',20000000);
 
class ab {
  var $x=0;
}
 
$x = new ab();
function f1() {
  global $x;
  for($i=0; $i<LOOP; ++$i) {
    $z = $x instanceof ab 
  }
}
function f2() {
  global $x;
  for($i=0; $i<LOOP; ++$i) {
    $z = is_a($x, 'ab') 
  }
}
$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
No test results (yet)
50%
updown
50%