Page 1 of 1
Cycles per instruction
Posted: Thu May 28, 2009 2:32 pm
by tiroxita
Hi all,
I would like to know if it is possible to find out the clock cycles of instructions of the PHP or even better a script or funtion that gives me the cycles of a segment of my code.
Thanks in advance
Re: Cycles per instruction
Posted: Thu May 28, 2009 2:58 pm
by alex.barylski
Not in PHP.
You would have to use xdebug which returns microseconds, which is not quite clock cycles but close enough to detecting problematic hot spots in your codebase.
You could probably get away with using microtime() in PHP itself if you want to quickly profile a small section of code.
Re: Cycles per instruction
Posted: Thu May 28, 2009 3:02 pm
by tiroxita
Yes, rigth now I am using microtime. My problem is that I would like to compare the complexity of some scripts, and execution time migth not be as accurate as I need since other processes might influence the result.
But thank for the quick reply
Re: Cycles per instruction
Posted: Thu May 28, 2009 11:33 pm
by alex.barylski
Even if you went as low level as using RDTSC instruction you would potentially get skewed results...you need to profile under a single process type system like MSDOS for that not to happen.
This is why when you profile repetitions are important.
You run 500 million tests on a function and take the average...if of those 500 million 30 times a cron service or something background gets invoked and chews up some clock cycles...so what...they won`t affect the results that much...you might also look into standard deviation to help you weed out the questionable results before calculating your average.
Re: Cycles per instruction
Posted: Fri May 29, 2009 3:44 am
by tiroxita
Ok thanks,
I think I will stick to the time measurement and do some statistical analysis then.
see you
Re: Cycles per instruction
Posted: Fri May 29, 2009 3:17 pm
by kaisellgren
When I want to have precise timing calculations on execution, I shut down everything I have running on background. I made an application that shut downs a wide variety of services - even the windows time, audio, theme, etc so only the core services and processes are running. After that, I disable access to core 1 for all processes except for the web server. This way I ensure no other process can interefere with my PHP execution (I have a quadie). Also, I set my web server to have very high priority. After all this, I run repetitious times the program I want to test and I take the average execution time and these averages barely vary between each other.
You also need to disable server logging, sql logging, caching, etc.
This might not be as precise as you want, but you can't really do any better than that.