Você pode ler este post em português também.
This post will show you a benchmarking among the attribution ways supported by PHP:
a) Simple attribution (ex.: $j = $j + 1);
b) Right association attribution (ex.: $j += 1);
c) Non-associative attribution (ex.: $j++);
- PC: Dell Optiplex 755;
- Environment: Bash, without X. Ext4 filesystem;
Linux optiplex755 188.8.131.52-68.fc13.x86_64 #1 SMP Thu Feb 17 15:03:58 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux
PHP 5.3.5 (cli) (built: Jan 7 2011 18:46:32)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
with Xdebug v2.1.0, Copyright (c) 2002-2010, by Derick Rethans
All the files used and generated by the test can be downloaded here. The applied methodology follows:
1) Turn off the PC by one minute;
2) @ bash:
for i in `seq 1 100`; do echo $i && php t1.php >> t1_output01.log; done;
3) Turn off the PC by one more minute;
4) @ bash:
for i in `seq 1 100`; do echo $i && php t1.php >> t1_output02.log; done;
5) Turn off the PC again, by one more minute;
6) @ bash:
for i in `seq 1 100`; do echo $i && php t1.php >> t1_output03.log; done;
The t1.php, t2.php and t3.php has each one three log files with its execution times. The 300 results of each script got ordered by by its execution time (ascendant way) and throwed out the 100 best and the 100 worst values, giving to us only the 100 best average execution times.
The graph shows that the use of “($j += 1)” or “($j++)” method can give you 0.02 second of advantage, in average.
We are going to modify our Coding Standards documents to preferring one of advantage methods that I have showed in this comparison, saving even more processing time.