1831338 Members
3122 Online
110024 Solutions
New Discussion

Default clock resolution

 
Rick Burge
Occasional Advisor

Default clock resolution

Clock () indicates that the "potential" resolution is in microseconds but the default resolution is 10 milliseconds. Assuming that my machine is operating at a speed much higher than 1Mhz how do I set the default resolution to something better than 10 ms? My Visual C on my laptop at least gives me 1ms resolution.

Thanks,
Rick
3 REPLIES 3
Andy Monks
Honored Contributor

Re: Default clock resolution

clock(3c) is just a wrapper for times(2). Have a look at times(2) as that looks like it's in ticks (which is cpu dependent).

Or you look at pstat() which can get the same, but probably has too much overhead.

Andy
Rick Burge
Occasional Advisor

Re: Default clock resolution

Thanks much for you reply... I had previously looked at this as an alternative only to discover that while it references a different definitions - CLK_TCK, it too is providing a 10ms resolution. What got me started on my question was the comment in clock() that indicates CLOCKS_PER_SECOND is defaulted at 10ms. This implies to me that perhaps the tick resolution could be set to a different value (within limits of course) by some system configuration parameter.

Ciao,
Rick
Andy Monks
Honored Contributor

Re: Default clock resolution

Looking at the time.h header file, you can see :-

#ifndef
#define CLOCKS_PER_SEC 1000000

Therefore, it looks like you might be able to override the value with your own.

Worth a try.