Boost C++ Libraries: Ticket #1962: Doesn't measure wall clock time https://svn.boost.org/trac10/ticket/1962 <p> The attached program, when run on my tickless (kernel 2.6.24) dual-core linux system, demonstrates that <code>boost::timer</code> isn't measuring what we want it to. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/1962 Trac 1.4.3 Dave Abrahams Wed, 28 May 2008 00:23:46 GMT attachment set https://svn.boost.org/trac10/ticket/1962 https://svn.boost.org/trac10/ticket/1962 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">thread4.cpp</span> </li> </ul> Ticket r.jordans@… Wed, 29 Oct 2008 09:53:23 GMT <link>https://svn.boost.org/trac10/ticket/1962#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/1962#comment:1</guid> <description> <p> The problem here is a generic one. The timer class uses clock() to measure time and this function is defined differently for Windows and Unix systems. On Windows it is defined as the wall clock time while on most Unix derivatives the total CPU time of the process is used. </p> <p> A simple example: (test_clock.c) #include &lt;time.h&gt; #include &lt;stdio.h&gt; #include &lt;unistd.h&gt; </p> <p> int main(int argc, char <strong>argv) { </strong></p> <blockquote> <p> time_t start = clock(); </p> </blockquote> <blockquote> <p> printf("Sleeping 1 second... "); fflush(stdout); </p> </blockquote> <blockquote> <p> sleep(1); </p> </blockquote> <blockquote> <p> printf("done\n"); printf("Time elapsed: %f\n", (clock()-start)/((float)CLOCKS_PER_SEC) ); </p> </blockquote> <blockquote> <p> return 0; </p> </blockquote> <p> } </p> <p> Will result in the following output: roel@localhost:~ $ ./test_clock Sleeping 1 second... done Time elapsed: 0.000000 </p> <p> Which is a completely different concept of time when compared to the result on Windows. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Beman Dawes</dc:creator> <pubDate>Sat, 06 Jun 2009 12:02:01 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/1962#comment:2 https://svn.boost.org/trac10/ticket/1962#comment:2 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">wontfix</span> </li> </ul> <p> &lt;timer.hpp&gt; measures whatever time std::clock measures. Unfortunately, this varies from system to system. </p> <p> The fix is to retire &lt;timer.hpp&gt;, and replace it with a much better set of facilities based on C++0x &lt;chrono&gt;. </p> <p> I've been working on these facilities in svn.boost.org/svn/boost/sandbox/chrono </p> <p> Currently, the header is &lt;boost/chrono/timer.hpp&gt;. It supplies: </p> <ul><li>process_clock: capturing real, user-CPU, and system-CPU clocks. </li><li>process_timer: capturing elapsed real, user-CPU, and system-CPU times. </li><li>run_timer: convenient reporting of process_timer results. </li></ul><p> I'm probably going to move these to a new Boost.Timer library. </p> <p> --Beman </p> Ticket