• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
40 Tips for PHP Optimization

#3
[eluser]Unknown[/eluser]
[quote author="walesmd" date="1192482883"]40. When incrementing or decrementing the value of the variable $i++ happens to be a tad slower then ++$i. This is something PHP specific and does not apply to other languages, so don't go modifying your C or Java code thinking it'll suddenly become faster, it won't. ++$i happens to be faster in PHP because instead of 4 opcodes used for $i++ you only need 3. Post incrementation actually causes in the creation of a temporary var that is then incremented. While pre-incrementation increases the original value directly. This is one of the optimization that opcode optimized like Zend's PHP optimizer. It is a still a good idea to keep in mind since not all opcode optimizers perform this optimization and there are plenty of ISPs and servers running without an opcode optimizer.
[/quote]
This's false for other languages as it's not php specific. In fact, you really get an optimization with ++i instead of i++ in C and C++ code, because the first to a simple add (and often an atomic one), but the second makes an assignment and an add. Things can be of course optimized the compilers, but with ++i you're sure to have the fatest code in all cases.


Messages In This Thread
40 Tips for PHP Optimization - by El Forum - 10-15-2007, 10:14 AM
40 Tips for PHP Optimization - by El Forum - 10-15-2007, 11:28 AM
40 Tips for PHP Optimization - by El Forum - 10-15-2007, 11:28 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.