Sign in to follow this  
donjonson

clock() ???

Recommended Posts

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this