clock time in milliseconds into a c program

Alin-Adrian Anton aanton at spintech.ro
Fri Jan 21 03:43:32 PST 2005


Claudiu Dragalina-Paraipan wrote:
> Or you can use PERFMON. Check manual page for perfmon.
> It gives you access to internal counters of CPU.
> 
> Of course this is a subjective measurement, since, AFAIK, the counters
> are not kept separately for every process, but for entire system,
> including kernel.
> Maybe repeating the same measurement for many times, with a system
> running no other CPU consumers, you will get a more accurate
> measurement
> 

As I said, multiple measurements provide better accuracy. Much better.

And as Joseph Koshy pointed out, the RDTSC instruction (works on Pentium 
i think) may even provide better accuracy then just measuring time. 
Using it in a cycle of measurements would provide relevant output, and 
perhaps more accurate then PERFMON (because of direct CPU access).

clock_gettime also provides nanoseconds resolution, as pointed out.


-- 
Alin-Adrian Anton
GPG keyID 0x1E2FFF2E (2963 0C11 1AF1 96F6 0030 6EE9 D323 639D 1E2F FF2E)
gpg --keyserver pgp.mit.edu --recv-keys 1E2FFF2E

Never ask a man what OS he uses. If it's FreeBSD, he'll tell you.
If it's not, why embarrass him? ..I'm sorry..


More information about the freebsd-hackers mailing list