time stamping

Started by
7 comments, last by kindfluffysteve 21 years, 8 months ago
how do i know the time to the nearest milisecond? obviously using c''s time functions i can know what time it is to the nearest second, but to the milisecond, i dont know.
Advertisement
Under windows you have to use timeGetTime() but set the precision first with timeBeginPeriod(1). That sets the resolution to 1 millisecond intervals.
Stephen ManchesterSenior Technical LeadVirtual Media Vision, Inc.stephen@virtualmediavision.com(310) 930-7349
thanks, i will use this most probably. does anybody know a cross platform equivelent? or the way this would achieved in linux as im interested in other platforms also.
clock()/(CLOCKS_PER_SEC/1000)
should give you the milliseconds since the program started...i think.
that seems logical, is that available across platforms?
With something as simple as getting the number of milliseconds since the OS started (or time in general) you should write a class (or function) to encapsulate the OS-specific details.

Dire Wolf
www.digitalfiends.com
[email=direwolf@digitalfiends.com]Dire Wolf[/email]
www.digitalfiends.com
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...
well that would make things easy - but curriously in TIME.H for visual c 6 it appears as far as i can tell to blindly say that clocks per second =1000.

im a bit vague on comp architecture. Is this true for all?
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
Widelands - laid back, free software strategy

This topic is closed to new replies.

Advertisement