Is there a way to measure the wall time between two points in a multi-threaded program in milli-seconds resolution? I am familiar with boost time_t, but its resolution is seconds, not milli-seconds. Methods from MKL library are welcome.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
On any modern POSIX system (like Linux), call clock_gettime with
CLOCK_MONOTONIC.[update]
By “wall time”, I assume you mean the time that actually elapses between two points. If you mean reading the actual time of day, use
CLOCK_REALTIMEinstead ofCLOCK_MONOTONIC. (The difference is how they behave if the user should change the system clock in the middle of your measurement.CLOCK_REALTIMEwill reflect that change whileCLOCK_MONOTONICwill not.)[update 2]
C++11 has built-in facilities for this in the std::chrono namespace. So if you have C++11, that is the most portable and future-proof option.