views:

21

answers:

1

Is this normal to get different results each time I execute my code?

I've written a small piece of code and whenever I run it, I get different results. Say I call two different functions in my code, sometime's the cost of Func1 is 44%, Func2 is 25%, sometimes it's 38%, 33% respectively!

What should I do to get more accurate results?

A: 

In most cases it's impossible to recreate the same results on a dynamic website, various factors like the amount of records in a database and background tasks will skew results. To help make sense of the XDebug results it's probabaly worth installing a nice frontend.

I use Webgrind: http://code.google.com/p/webgrind/

Preview: http://jokke.dk/media/2008-webgrind/webgrind_large.png

It might be worth putting a few var_dumps inside the function to figure when the varied results occur, if you can isolate them you'll know how to speed up the whole function.

Kieran Allen
Is this some kind of web-based kcachegrind?
David Weng
yeah, it's exactly that.
Kieran Allen