The PHP Benchmark can help you run faster

19-year old Chris Vincent from down there Brisbane, Australia put together a really interesting programming tool aka cheat sheet aka PHPBench.com, by comparing the different approaches we usually adopt while coding in PHP.

Apart from the extremely useful results showcased there, the whole page is a piece of simplicity sex, with to-the-point typography and clear colour cues for everything.

Since I don’t consider myself a fluent PHP programmer, imagine my shock when I saw that the while(list => each) loop is *so* much faster than my beloved foreach in modifying loops. 

Foreach, you’re out!

P.S. I guess you can take them all results with a grain of salt, but they seem pretty much well worked on and accurate. Thoughts?

7 Responses to “The PHP Benchmark can help you run faster”


  1. Gravatar

    That’s old news but nobody cares. By the time you optimize a web application you can get a 2x faster server for the same money. So… Speed of coding not speed of code. Foreach rocks ;)

  2. Gravatar

    @Vangelis

    Also noticed that pre-calculated array lengths, a long-standing optimization for loops, actually have no positive effect in PHP efficiency. Quite a shock too.

    I’m right with you on the quick coding bit, but experience has proven us wrong - when coding in a hurry, you’ll pay for it later.

    Twitter, anyone? ;)

  3. Gravatar

    “when coding in a hurry, you’ll pay for it later”

    Indeed, as they say:

    “Programming is like sex, one mistake and you have to support it for the rest of your life.”(Michael Sinz) :P

  4. Gravatar

    You confused me. The conclusion at the phpbench.com is quite the opposite from yours:

    “In all cases I’ve found that the foreach loop is substantially faster than both the while() and for() loop procedures. One thing to note is that when using an entire loop from the start it’s extremely good to use the reset() function in all examples”

    What am I (or you) misinterpreting?

  5. Gravatar

    @nikan

    That’s for the Read Loop, when you just want to traverse an array and do some stuff with its values. Check the Modify Loop, that’s what I meant.

  6. Gravatar

    the ‘foreach’ results are now the fastest.

  7. Gravatar

    @Peter Uhm, I still see ‘foreach’ giving a +632% overhead in Modify Loops. What did I lose?


Got something to say?

Please say it in English, the one and only language of this blog. If your comment is in greek or swedish or esperanto, I claim the right to edit it and translate it to english. Thank you.