Link to home
Start Free TrialLog in
Avatar of groundhogday
groundhogday

asked on

Need a milisecond timer

Does anyone know what function I can use beside clock() under Linux to track time interval?  The CLOCKS_PER_SEC value is set to 1000000 and overflows quickly.  I need to track at least 30 days but also need milisecond level.  It would be nice if 1000000 can be changed to 1000.  Thanks.
Avatar of GaryFx
GaryFx

Try using gettimeofday.  You will have to maintain two separate variables, because (if I've done my math right), thirty two bits worth of microseconds holds less than two hours worth of time.

Gary
You do not have to maintain 2 varaibles since by using gettimeofday you get a struct that holds both the seconds and the microseconds, so you win 2 times - first you have got microsecond resolution, and second it lasts about 200-300 years...

Hope this helps,
Liron.
Avatar of groundhogday

ASKER

Can someone show sample code using gettimeofday to track time interval?
ASKER CERTIFIED SOLUTION
Avatar of slironm
slironm

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
slironm, Sorry, but I've been away for a while.  Thanks for the help.