• Advertisement
Sign in to follow this  

clock() ???

This topic is 4652 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

Is this a working function with c++ and windows? I would like to make a timer that is accurate regardless of the machine it is running on. what function would i use for this?

Share this post


Link to post
Share on other sites
Advertisement
Queryy... only work on Win32. clock(), if it's available, usually has pretty poor resolution.

The closest you can come to a portable time function with good resolution is probably ftime(). (It may be called _ftime() on some systems).

However, you're probably better off writing a function called MyTimer() that returns the time, and implement it separately on each OS you're interested in (say, using #if defined(WIN32) ...). That way, you can use the best timer for each OS.

Share this post


Link to post
Share on other sites
clock() does not return the wall clock time.

Don't use it unless what it returns, is what you want. clock() gives you the amount of processor time the process has used. THIS IS NOT USEFUL FOR TIMING.

The common solution is to use QueryPerformanceCounter on win32, and gettimeofday() on everything else.

The latter is typically accurate to 1 microsecond on Linux - I don't know about other OSs.

Mark

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement