开发者

measuring wall time in a multi-threaded environment

开发者 https://www.devze.com 2023-04-10 01:04 出处:网络
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 reso开发者_开发问答lution is seconds, not m

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 reso开发者_开发问答lution is seconds, not milli-seconds. Methods from MKL library are welcome.


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_REALTIME instead of CLOCK_MONOTONIC. (The difference is how they behave if the user should change the system clock in the middle of your measurement. CLOCK_REALTIME will reflect that change while CLOCK_MONOTONIC will 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号