views:

120

answers:

4

Is it possible to determine the throughput of an application on a processor from the cycle counts (Processor instruction cycles) consumed by the application ? If yes, how to calculate it ?

+2  A: 

Simple:

#include <time.h>
clock_t c;
c = clock(); // c holds clock ticks value
c = c / CLOCKS_PER_SEC; // real time, if you need it

Note that the value you get is an approximation, for more info see the clock() man page.

Yuval A
+2  A: 

If the process is entirely CPU bound, then you divide the processor speed by the number of cycles to get the throughput.

In reality, few processes are entirely CPU bound though, in which case you have to take other factors (disk speed, memory speed, serialization, etc.) into account.

Jerry Coffin
Methods such as clock() give pretty good estimations on cpu/user time clock ticks - discounting any other factors (I/O, switching, etc...)
Yuval A
@Yuval: Right -- `clock()` also has the advantage that it normally delays for things like memory reads into account, which counting cycles in the CPU manual won't.
Jerry Coffin
@Jerry: Thanks for highlighting the impact of other factors also. It is true that in reality only few processes are entirely CPU bound !
S.Man
A: 

Some CPUs have internal performance registers which enable you to collect all sorts of interesting statistics, such as instruction cycles (sometimes even on a per execution unit basis), cache misses, # of cache/memory reads/writes, etc. You can access these directly, but depending on what CPU and OS you are using there may well be existing tools which manage all the details for you via a GUI. Often a good profiling tool will have support for performance registers and allow you to collect statistics using them.

Paul R
A: 

If you use the Cortex-M3 from TI/Luminary Micro, you can make use of the driverlib delivered by TI/Luminary Micro. Using the SysTick functions you can set the SysTickPeriod to 1 processor cycle: So you have 1 processor clock between interrupts. By counting the number of interrupts you should get a "near enough estimation" on how much time a function or function block take.

BaumS