phpbench.com

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

phpbench.com

Post by pickle »

This looks interesting - some interesting revelations: http://www.phpbench.com/
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
Mordred
DevNet Resident
Posts: 1579
Joined: Sun Sep 03, 2006 5:19 am
Location: Sofia, Bulgaria

Re: phpbench.com

Post by Mordred »

Wow, so much work into so flawed a setup...
Apart from comparing apples to oranges, he sometimes compares apples to friday.

I'm far from impressed.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: phpbench.com

Post by pickle »

How is it flawed? I'm not going to say I think it's perfect, but he seems to be doing a pretty decent job of comparing multiple ways of doing the same thing.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
Mordred
DevNet Resident
Posts: 1579
Joined: Sun Sep 03, 2006 5:19 am
Location: Sofia, Bulgaria

Re: phpbench.com

Post by Mordred »

Well, look carefully at the snippets he compares - most often than not, they are simply not equivalent, up to the point of being radically different

Code: Select all

foreach($aHash as $val);
and

Code: Select all

$key = array_keys($aHash);
$size = sizeOf($key);
for ($i=0; $i<$size; $i++) $tmp[] = $aHash[$key[$i]];
And look at this little gem:

Code: Select all

while($i < 2000) {
        isSet($notSet);
        is_array($notSet);
        ++$i;
    }
Wow, eight times slower than isset(), seriously! How about a nice cup of the && operator?

And what is this supposed to mean:

Code: Select all

class SomeClass2 {
    function f() {
 
    }
}
...
        $obj =& $someClass->f();

Tests need to be done with real code, not with empty loops and empty functions. Data should be read and written to, not merely aliased. Ideally, standalone scripts should be generated and called from an "outside" loop, just like they would be executed in the real life.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Re: phpbench.com

Post by superdezign »

Well, at least the website is pretty. :/

I just feel as though it's a bit.. random. He doesn't seem to be trying to prove any point in particular, and it doesn't really give me any idea into what to and not to do, especially after seeing the details that ~Mordred has pointed out.
User avatar
Bill H
DevNet Resident
Posts: 1136
Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:

Re: phpbench.com

Post by Bill H »

Well, at least the website is pretty. :/
Degustibus non disputandum est.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: phpbench.com

Post by RobertGonzalez »

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
Nevermind the fact the foreach makes a copy of the array in a all cases. And because of that, reset() means nothing to it.

I personally think his comparisons are crap. He should the same exact array and process them in the exact same manner (barring the loop construct of course), doing this many times over to get a clean average.

He should also post the resources that are on the machine he is testing with.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: phpbench.com

Post by onion2k »

While the tests do seem to demonstrate (in a flawed manner) that there can be speed differences between logically similar things, he has ignored things like resource usage and code readability. One method might well be a couple of hundred microseconds faster, but if it's using 5 times the RAM it might not be a very sensible saving on a busy site. Likewise, a snippet might save you a little CPU time but if it's at the expensive of having readable, maintainable code, is it really worth doing?
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: phpbench.com

Post by Eran »

In my opinion this is a nice reference to have when the time comes for extreme optimization. In some edge cases it could be useful, like when fetching massive result sets that need to be iterated etc.
Post Reply