Pre-increment where possible

Take advantage of the fact that PHP allows you to post-increment ($i++) and pre-increment (++$i). The meaning is the same as long as you are not writing anything like $j = $i++, however pre-incrementing is almost 10% faster, which means that you should switch from post- to pre-incrementing when you have the opportunity, especially in tight loops and especially if you're pedantic about micro-optimisations!

Note that both the Zend Optimizer and IonCube PHP Accelerator will implement this optimisation for you.

 

Next chapter: Don't think that using references will lower your RAM usage >>

Previous chapter: Get your loops right first

Jump to:

 

Home: Table of Contents

Follow us on Identi.ca or Twitter

Username:   Password:
Create Account | About TuxRadar