file_exists vs is_file (existing files with error ignore)

Submitted by Lito on Fri, 03/16/2012 - 15:45

f1 is slower than f2 by 232.94% (2.3 times slower)

Full source code as executed.
/* How many times the code under test should run in each function */
define('LOOP',1000000);
 
function f1() {
  for($i=0; $i<LOOP; ++$i) {
    @file_exists('/etc/passwd');
  }
}
function f2() {
  for($i=0; $i<LOOP; ++$i) {
    @is_file('/etc/passwd');
  }
}
$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
68.72%560280633208505.3.3-7+squeeze1
195.68%1100687372258php-5.3.6-phpbrew_compiled
208.19%1119432363225php-5.3.7-phpbrew_compiled
198.06%1115748374331php-5.3.8-phpbrew_compiled
168.56%1211394451068php-5.3.9-phpbrew_compiled
162.96%1117845425099php-5.3.10-phpbrew_compiled
212.6%1194864382233php-5.3.11-phpbrew_compiled
215.51%1195317378852php-5.3.12-phpbrew_compiled
197.71%1141016383269php-5.3.13-phpbrew_compiled
206.34%1159072378358php-5.3.14-phpbrew_compiled
192.31%1118701382709php-5.3.15-phpbrew_compiled
207.49%1203476391381php-5.3.16-phpbrew_compiled
211.51%1177974378149php-5.3.17-phpbrew_compiled
188.66%1192130412990php-5.3.18-phpbrew_compiled
194.7%1120221380127php-5.3.19-phpbrew_compiled
302.42%910647226290php-5.4.0-phpbrew_compiled
287.58%928864239655php-5.4.1-phpbrew_compiled
289.12%909721233787php-5.4.2-phpbrew_compiled
283.7%956509249285php-5.4.3-phpbrew_compiled
327.26%950366222434php-5.4.4-phpbrew_compiled
284.95%960283249459php-5.4.5-phpbrew_compiled
312.93%922966223516php-5.4.6-phpbrew_compiled
300.27%896755224035php-5.4.7-phpbrew_compiled
300.04%894189223523php-5.4.8-phpbrew_compiled
306.18%953859234836php-5.4.9-phpbrew_compiled
50%
updown
50%