merkuro
merkuro

Reputation: 6167

What are the absolute and relative costs of different operations in PHP?

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!

Upvotes: 0

Views: 238

Answers (5)

Adriano Varoli Piazza
Adriano Varoli Piazza

Reputation: 7429

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.

Upvotes: 2

dicroce
dicroce

Reputation: 46770

“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.

Upvotes: 0

Marc Towler
Marc Towler

Reputation: 705

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?

Upvotes: 0

Stefan Gehrig
Stefan Gehrig

Reputation: 83622

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

Upvotes: 3

Related Questions