How to get number cycle in my c program ?

Dear all,
I like to get how many cycle does my machine needs to run my c program?
Please, give me any clue how to do it?

The following here is PC detail;
- AMD Turion 64 X2 Mobile Technology
- GCC is my compiler used
- Run on Linux platform(Ubuntu)


Thanks for any respond.

What do you mean by "cycle"?

You can always check a timer, launch the program, wait for it to quit, then check and compare the timer again. This will give your answer in whatever units the timer uses --which is usually based upon how fast the CPU's little quartz vibrates.
Using the time command will offer you the user space time and the kernel time which your programm has been consumed.
When knowing the CPU cycle time, you may appoximate the number of cycles.

Excample: time myprog

Note: When your app is mutlithreaded, then time may show just the consumed time of the parent thread/process (tested in AVR32 Linux).

The time command provides just milliseconds. If you need more precision you can use the C functions setitimer() and getitimer() at the beginning and the end of your code to get the consumed time in microseconds.

Joe.
Last edited on
Thank you for the responds,
What i meant by number of cycle is, the time that that is needed by processor to run complete c program, the return information should be in number of instruction cycle (http://en.wikipedia.org/wiki/Instruction_cycle), basically i want to have a high precision of timing.

to joem: settimer() and gettimer () functions, does return High resolution timing?
Sorry, not to clearly point out the problem

Topic archived. No new replies allowed.