preincrement vs postincrement

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

f2 is slower than f1 by 12.34%

Full source code as executed.
define('LOOP',10000000);
 
function f1() {
  for($i=0; $i<LOOP; ++$i) {}
}
 
function f2() {
  for($i=0; $i<LOOP; $i++) {}
}
 
$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
15.79%341109339496275.3.5-1ubuntu7.2
33.77%285245438157935.3.3-7
7.85%473864351104865.3.5-1ubuntu7.2
34.79%276152837222555.3.3-7+squeeze1
6.98%488622522715php-5.3.6-phpbrew_compiled
7.16%496264531785php-5.3.7-phpbrew_compiled
35.21%471111637001php-5.3.8-phpbrew_compiled
11.08%472918525312php-5.3.9-phpbrew_compiled
9.01%478150521215php-5.3.10-phpbrew_compiled
15.01%459611528589php-5.3.11-phpbrew_compiled
14.86%458835526999php-5.3.12-phpbrew_compiled
15.76%456263528162php-5.3.13-phpbrew_compiled
15.64%453086523937php-5.3.14-phpbrew_compiled
13.45%465846528513php-5.3.15-phpbrew_compiled
11.71%470741525858php-5.3.16-phpbrew_compiled
10.31%476918526079php-5.3.17-phpbrew_compiled
7.83%486833524973php-5.3.18-phpbrew_compiled
12.03%469406525867php-5.3.19-phpbrew_compiled
18.13%211167249458php-5.4.0-phpbrew_compiled
32.3%321930243325php-5.4.1-phpbrew_compiled
6.24%261468246112php-5.4.2-phpbrew_compiled
32.54%323839244340php-5.4.3-phpbrew_compiled
16.47%209379243858php-5.4.4-phpbrew_compiled
17.83%205876242591php-5.4.5-phpbrew_compiled
17.32%207582243533php-5.4.6-phpbrew_compiled
17.23%206165241697php-5.4.7-phpbrew_compiled
91.17%206437394654php-5.4.8-phpbrew_compiled
39.8%338636242223php-5.4.9-phpbrew_compiled
50%
updown
50%