tag:blogger.com,1999:blog-3365890222783870731.post4659942787352547796..comments2023-12-20T18:00:19.665+01:00Comments on The Typethinker: Timing a section of code in C++Thomas ten Catehttp://www.blogger.com/profile/02609144861191873031noreply@blogger.comBlogger2125tag:blogger.com,1999:blog-3365890222783870731.post-64477543003703998422010-05-21T10:45:51.536+02:002010-05-21T10:45:51.536+02:00I'm already using clock_gettime(CLOCK_REALTIME...I'm already using clock_gettime(CLOCK_REALTIME, ...) above. Mainly because CPUTIME is indeed a tricky concept.<br /><br />I didn't check clock_getres, but the resolution of clock_gettime is high enough indeed. When I forgot to actually declare a TimedSection variable (creating a temporary instead), it measured a nonzero time between construction and destruction.Thomas ten Catehttps://www.blogger.com/profile/02609144861191873031noreply@blogger.comtag:blogger.com,1999:blog-3365890222783870731.post-49565056657743899632010-05-21T08:10:56.554+02:002010-05-21T08:10:56.554+02:00It might be nice to know boost's progress_time...It might be nice to know boost's progress_timer.<br /><br />http://www.boost.org/doc/libs/1_43_0/libs/timer/timer.htm#Class%20progress_timer<br /><br />It's not quite as handy: it prints using seconds rather ms, and prints to cout by default, and doesn't have that nice labelling option, but it is simple...<br /><br />For more precise things, you might also want to use clock_gettime(CLOCK_PROCESS_CPUTIME_ID, ptr_to_timespec) or clock_gettime(CLOCK_REALTIME, ptr_to_timespec) from unistd.h on unix or their win32 counterparts QueryPerformanceCounter(ptr_to_LARGE_INTEGER) or GetSystemTime(ptr_to_SYSTEMTIME) <br /><br />(I've never quite figured out what exactly cpu time is supposed to mean to these functions, but they're extremely highres, which can be nice...)Eamon Nerbonnehttps://www.blogger.com/profile/00388124191987595398noreply@blogger.com