Archived

This topic is now archived and is closed to further replies.

kindfluffysteve

time stamping

Recommended Posts

Guest Anonymous Poster
clock()/(CLOCKS_PER_SEC/1000)
should give you the milliseconds since the program started...i think.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
clock() and CLOCKS_PER_SEC are ANSI C standard and are in time.h
Wether the includes/libs that come with a specific compiler implement them properly is another story though...

Share this post


Link to post
Share on other sites
The Linux bits/time.h says:

/* ISO/IEC 9899:1990 7.12.1:
The macro `CLOCKS_PER_SEC'' is the number per second of the value
returned by the `clock'' function. */
/* CAE XSH, Issue 4, Version 2:
The value of CLOCKS_PER_SEC is required to be 1 million on all
XSI-conformant systems. */
# define CLOCKS_PER_SEC 1000000l

Don''t ask me what XSI is
But anyway, this sounds as if clock() could actually be usable. Mind you though: just because clock() returns a value 1000000 greater every second doesn''t actually mean that it works with microsecond precision.

FYI, you can also use gettimeofday() on *nix systems. The name is a bit misleading because it actually returns time based on the epoch (i.e. seconds since 1.1.1970). gettimeofday() also returns microseconds. On Linux, this should actually yield microsecond precision because the kernel polls the TSC or the PIT (depending on the system) to get a precise value.

cu,
Prefect

Share this post


Link to post
Share on other sites