Discussion:
Any standard way of geting timer resolution finer than 1 second?
(too old to reply)
J***@msn.com
2006-03-08 16:23:40 UTC
Permalink
Raw Message
Is there any standards conformant way to get times (system or clock
ticks, etc..) with a finer granularity than one second?

I'm working with a 3rd party tool and trying to "profile" the code. I
have indirect access to the standard time function but that just gives
me seconds.

I'm needing as fine a measurement as possible.
Keith Thompson
2006-03-08 21:06:26 UTC
Permalink
Raw Message
Post by J***@msn.com
Is there any standards conformant way to get times (system or clock
ticks, etc..) with a finer granularity than one second?
I'm working with a 3rd party tool and trying to "profile" the code. I
have indirect access to the standard time function but that just gives
me seconds.
I'm needing as fine a measurement as possible.
No. You'll need to use some system-specific function. Try a
newsgroup specific to your system.

Your system may also have a dedicated profiler tool.
--
Keith Thompson (The_Other_Keith) kst-***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
David R Tribble
2006-03-09 00:23:21 UTC
Permalink
Raw Message
Post by Keith Thompson
Post by J***@msn.com
Is there any standards conformant way to get times (system or clock
ticks, etc..) with a finer granularity than one second?
No. You'll need to use some system-specific function. Try a
newsgroup specific to your system.
MS/Win32 has GetSystemTime() and GetSystemTimeAsFileTime(),
and Unix has gettimeofday() or clock_gettimeofday().

-drt

Roland Illig
2006-03-08 21:08:57 UTC
Permalink
Raw Message
Post by J***@msn.com
Is there any standards conformant way to get times (system or clock
ticks, etc..) with a finer granularity than one second?
I'm working with a 3rd party tool and trying to "profile" the code. I
have indirect access to the standard time function but that just gives
me seconds.
I'm needing as fine a measurement as possible.
If you're using ISO C alone -- no. There is not even the guarantee that
the granularity is one second. ("The range and precision of times
representable in clock_t and time_t are implementation-defined." [7.23.1p4])

If you're on a POSIX or Win32 system, things look different, of course.

Roland
Douglas A. Gwyn
2006-03-08 20:42:26 UTC
Permalink
Raw Message
Post by J***@msn.com
Is there any standards conformant way to get times (system or clock
ticks, etc..) with a finer granularity than one second?
Not if the system doesn't provide it!
Look up clock() in <time.h> and especially CLOCKS_PER_SEC,
which tells you the resolution (typically 60 ticks/second).
Post by J***@msn.com
I'm needing as fine a measurement as possible.
POSIX specifies times(), which reports the system and user
times used by the current process with and without the
aggregate times of all its descendants.

Note also that if you iterate an operation you can get
better statistics, especially when the operation takes
at most a few clock ticks. However, sometimes the
measurement gets fouled up by caching (code runs much
faster after the first iteration).
Loading...