CXO

Clever PHP performance tip

If you're running a tight loop with a lot of iterations, this PHP tip can give you enough extra performance to justify the non-standard coding.

TechRepublic member and frequent commenter Gerardo Tasistro sent in some very interesting PHP performance numbers. He compared the speed of two empty loops and discovered that, when using a calculation for the end condition, the loop ran about 25% faster than when using a comparison. For example:

for($i=0;$maxCount-$i;$i++) {
}

If you're running a tight loop with a lot of iterations, this little trick can give you enough extra performance to justify the non-standard coding.

J.Ja

About Justin James

Justin James is the Lead Architect for Conigent.

Editor's Picks

Free Newsletters, In your Inbox