Jump to content
  • Advertisement

Archived

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

kindfluffysteve

time stamping

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

If you intended to correct an error in the post then please contact us.

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 this post


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

Share this post


Link to post
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 this post


Link to post
Share on other sites
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
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 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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!