tags:

views:

86

answers:

5

Do you have a nice class you use for measuring time a PHP script loads certain blocks of code? Would you care to share what YOU use?

+4  A: 

Xdebug and KCacheGrind. Doesn't get much better than that.

Jani Hartikainen
A: 

My first choice for profiling php would be xdebug.

Björn
A: 

I use my IDE's built in PHP profiler. Works excellently, will jump right to the slow spots in your code, show and highlight them, all kinds of interactive features.

tj111
Sounds nice, which IDE is that? I have phpdesigner which is amazing, it has a bunch of debug stuff including xdebug but I don't know how to use any of it
Jack Ferrari
PhpED, that's the companies site the makes it.
tj111
+1  A: 

Profiling classes are okay, but the proper way to profile a web application would be to install xdebug. Keeps your code clean from Benchmark::start, etc ...

You will need Xdebug and something to view the output, for that I recommend Webgrind. Kcachegrind is another popular choice.

There are plently of resources for you out there.

Google Search for "xdebug profiler"

Happy profiling and don't forget the saying "premature optimization is evil" :-)

The Pixel Developer
A: 

What I use, regardless of language, is stackshots. What you want to find out is which lines of code account for the largest fractions of execution time. (Note that these fractions will typically sum up to more than 100%.) Such a line, if avoided, would shorten execution time by that amount, so any such line is a good candidate for optimizing.

The fraction of time a line takes does not have to be known with high precision. In fact, if I take stack samples manually, as soon as I see a line of code show up on more than one sample, I know it is a significant time-taker. The more wasteful it is, the fewer samples are needed to expose it.

Mike Dunlavey