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
Cycles per instruction
Moderator: General Moderators
-
alex.barylski
- DevNet Evangelist
- Posts: 6267
- Joined: Tue Dec 21, 2004 5:00 pm
- Location: Winnipeg
Re: Cycles per instruction
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.
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
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
But thank for the quick reply
-
alex.barylski
- DevNet Evangelist
- Posts: 6267
- Joined: Tue Dec 21, 2004 5:00 pm
- Location: Winnipeg
Re: Cycles per instruction
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.
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
Ok thanks,
I think I will stick to the time measurement and do some statistical analysis then.
see you
I think I will stick to the time measurement and do some statistical analysis then.
see you
- kaisellgren
- DevNet Resident
- Posts: 1675
- Joined: Sat Jan 07, 2006 5:52 am
- Location: Lahti, Finland.
Re: Cycles per instruction
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.
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.