40 Tips for PHP Optimization |
[eluser]Michael Wales[/eluser]
40 Tips for PHP Optimization Some of my favorites (many of these are mentioned in the EllisLab Developer Guidelines as well): Quote:9. See if you can use strncasecmp, strpbrk and stripos instead of regex
[eluser]leonglass[/eluser]
I am going to bookmark that for later. I think his point in 40 does apply to other languages as well as they also convert to less opcodes for prefix incrementing. It is something I have done as standard for a long time in Java.
[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. |
Welcome Guest, Not a member yet? Register Sign In |