#### Archived

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

# time stamping

This topic is 5919 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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.

##### Share on other sites
Under windows you have to use timeGetTime() but set the precision first with timeBeginPeriod(1). That sets the resolution to 1 millisecond intervals.

##### Share on other sites
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.

##### Share on other sites
clock()/(CLOCKS_PER_SEC/1000)
should give you the milliseconds since the program started...i think.

##### Share on other sites
that seems logical, is that available across platforms?

##### Share on other sites
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

##### Share on other sites
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 on other sites
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?

##### 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

1. 1
2. 2
Rutin
25
3. 3
4. 4
5. 5

• 10
• 13
• 19
• 14
• 9
• ### Forum Statistics

• Total Topics
632942
• Total Posts
3009339
• ### Who's Online (See full list)

There are no registered users currently online

×