I want to count CPU cycles used by arbitrary code
I want a compiler, or an addon for a compiler, or whatever, that will let me find the number of clock cycles used by my computer to execute a block of code. Example - in C++ I might want to see just how many clock cycles are taken to multiply two given numbers numbers
Code:
#beginClockCycleCounter I've never seen anything like this, but it would be useful as hell for something like deciding which algorithm is best to do something, or rating how fast a system should be to run it, etc |
Just the link you are looking for: http://devforums.amd.com/calinux.jsp
As long as you have an amd cpu. |
Well, your example is just useless - x*y has no defined sense of time of execution. Maybe you want just write function that will write result of rdtsc assembler command (is returned in edx:eax) to specified variable, and you will be able to measure difference. As I understand, precision is never better than 32 cycles, and if OS takes control away you get much more... But try increasing priority (OS- and permission- dependent).
|
What you need to use is gprof. You compile your program with the the -pg option, and when you run it, it creates a file called gmon.out. Then you run gprof on your executable, and it prints out of profiling graph with a breakdown of time spent in the various functions etc.
See here of more details. |
Awesome, thanks guys
|
All times are GMT -5. The time now is 11:14 PM. |