clock cycle count

Hello everybody!
Is there a way to count the clock cycles (that a program took to finish) in C?

thanx:o

Use the clock() function in time.h

hello, as fas as i know, clock() measures time in sec! is possible to return clock cycles?

thanx anyway jim:b:

No. read the man page - it returns CLOCKS_PER_SEC. This is implementation defined. There is no POSIX standard UNIX api that actually tracks clock ticks. You can use the following api calls to get what you want in different ways, but none actually returns real ticks of the CPU clock. If they do it is more coincidental than anything else. You have Windows in mind I think:

getrusage() - check out struct rusage
gettimeofday() - very fine grained time
times() - same granularity as clock()
but gives system + user time for both parent and children.

Also, check out the CLOCK_REALTIME macro in time.h and

getconf _POSIX_CLOCKRES_MIN

for your system - this tells you the finest time resolution available on your system.

Most computers these days have variable-speed clocks anyway for power-savings. My 1.6GHz Turion seems to spend most of its time at 800MHz.

thanx a lot jim for the help!:b: