tags:

views:

49

answers:

5

When running a micro time and catching it at the start of the a script then at the end of a script why does the time change every time you run the script?

Does it have to do with other items running? How it was processed?

+3  A: 

External factors cause time differences. Server load, memory management/paging are some examples of why it could be different.

easement
A: 

Probably both - could be due to other things going on with the server or it could be due to caching or other such things that would usually make the first run the slowest and subsequent runs faster.

Eric Petroelje
A: 

There are way too many factors that influence the amount of time a single php request takes. As long as the differences are not obviously a sign that something funky is going on (one req takes 100ms, the next one takes 1800ms) they are quite normal.

code_burgar
A: 

It is normal to have little difference for external reasons as other stated.

But if you have big differences or if you want to find a possible bottleneck (network latency, database overloaded, disk I/O, etc.) you may need to do a deeper investigation.

To do that, you need to profile you script with xdebug or other related tool.

Toto
A: 

Like other said, lots of things can change script runtime. A big one is Disk I/O and database access, and relative server load. I find when benchmarking things to take several reads and average them out. And compare the averages when checking for slow down / speed up.

Mark Story