PHP Benchmarking

July 14, 2010
There's only a few things that people want out of a PHP application, too bad for you that those few things encompass just about everything.

Not in any particular order. The good news is, I've spent a little time benchmarking PHP code to let you see first hand what the results are. Please note, I've ran these on a laptop, not a big time production server, so they make seem to have taken a bit. The number isn't the goal here, the comparison between them is. Some will be interesting, some will be the exact same as the other ones. At least you'll know (and have some ammunition) when somebody tells you "THAT'S NOT RITE!"

If you're interested in downloading the code I used to benchmark these elements, there's a -zip- file for that!

They won't be exact, as I repurposed some of them (i.e. different methods to concat strings, evaluate, etc).

String Concatenation


Iterations: 500,000
Concats per iteration: 20

Probably one of the more interesting benchmarks:

$temp = $mystring . " " . $mystring . " " (...)
Scored: 2.035299 Seconds


$temp = "{$mystring} {$mystring} (...)
Scored: 1.237544 Seconds


$temp = "$mystring $mystring (...)
Scored: 1.236022 Seconds


Other Concatenations


Iterations: 500,000
Concats per iteration: 1

Don't compare these with the previous, they're not necessarly related to them due to differing levels of concatenation.

$a = $a . $mystring;
Scored: 0.584638 Seconds


$a .= $mystring;
Scored: 0.575480 Seconds


String Encapsulation


Iterations: 50 Million

$a = '1234567890poiuytrewqasdfghjkl/.,mnbvcxz';
Scored: 7.486550 Seconds


$a = "1234567890poiuytrewqasdfghjkl/.,mnbvcxz";
Scored: 7.477590 Seconds


Conjunctive (Logical) Evaluations


Iterations: 50 Million

Performing logical evaluations on equivalent floats, that are not in variables.

Using: &&
Scored: 5.898687 Seconds


Using: AND
Scored: 5.799526 Seconds


Using: ||
Scored: 4.663750 Seocnds


Using: OR
Scored: 4.600031 Seconds


Using: ===
Scored: 4.065238


Using: ==
Scored: 4.217280


Using: !=
Scored: 3.874042


Using: !==
Scored: 3.863586


Using: <
Scored: 3.950963


Using: >
Scored: 4.029640


Using: <=
Scored: 4.288681


Using: >=
Scored: 4.290717


MOAR!


There's more to come. That's all for today, kiddies. If you have any suggestions, please contact me.
Name:

No comments yet! Be the first!