views:

146

answers:

5

I'm looking for a elaborate list comparing different operations in PHP. For example: echo vs. printf, ++$i vs $i++, a direct function call vs. object function call, array access vs. direct data access, global vs. local variables, mysql_fetch_assoc vs. mysql_fetch_row etc. Of course these figures probably highly depend on the used version, the OS, hardware and many other factors, but I saw lists like this for c/c++ and maybe there is something similar for PHP.

Update

Will leave this question open for two more days. Maybe we can get a few more of these usefull links!

+3  A: 

Perhaps this can help you with some of the functions/operators: http://www.phpbench.com/

Stefan Gehrig
Sorry for the late response still browsing the site. NICE find and thanks for sharing! As far as I can tell they lack a few things, but nevertheless it is exactly what I was looking for.
merkuro
And there's another on http://www.php.lt/benchmark/phpbench.php .
altermativ
A: 

why not run a few tests yourself comparing them? That way you know that for a machine with X specs runs echo at Y time whilst it does printf at Z time?

Marc Towler
Good point and I totally agree that it could give me a very clear picture for my equipment. However I also want to get a more broader view on these things (relative figures) in comparison with other OS/hardware. One more thing: With my lack of knowledge about the PHP architecture I don't think that I could come up with very good test-cases.
merkuro
A: 

“We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil." Donald Knuth.

The thing I like the most about this statement: Note that he says "small efficiencies". He's talking about code tuning... Essentially, I think he's arguing for getting your algorithm right from the beginning, but saving the code tuning for only when it's absolutely necessary.

dicroce
+2  A: 

Be careful! Some days ago, this article at google code appeared on just this subject. It was refuted almost immediately by this refutation. So watch out and test everytime.

Adriano Varoli Piazza
Interesting Resource!
altermativ