Boost C++ Libraries: Ticket #192: clock is not portable https://svn.boost.org/trac10/ticket/192 <pre class="wiki">On Win32 clock reports total elapsed time. On GNU/Linux clock reports consumed processor time by that process, and only reports time on the primary thread. Other threads always return 0, and time spent usleep'ing is not counted. The wording of the C/C++ standard is not without room for interpretation, and may even be interpreted to mean do whatever you can for clock. On Linux, and very possibly other *nix's, the function gettimeofday (in sys/time.h) should probably be used. code dump of my linux timer follows: template&lt;typename T&gt; struct HPTimer { i64 Now_us() { timeval now; MKH_THROWONFAILURE(gettimeofday (&amp;tvnow, 0)); return i64(now.tv_sec) * 1000000 + now.tv_usec; } T Snap() { timeval snap; //timezone zn; MKH_THROWONFAILURE(gettimeofday (&amp;snap, 0)); i64 now = i64(snap.tv_sec) * 1000000 + snap.tv_usec; i64 then = i64(prev_snap.tv_sec) * 1000000 + prev_snap.tv_usec; prev_snap = snap; return T(now - then) / 1000000; } protected: timeval prev_snap; }; </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/192 Trac 1.4.3 beman_dawes Wed, 08 Feb 2006 17:29:22 GMT status changed https://svn.boost.org/trac10/ticket/192#comment:1 https://svn.boost.org/trac10/ticket/192#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">closed</span> </li> </ul> <pre class="wiki">Logged In: YES user_id=51042 This is what the C++ Committee's library working group calls a "genetic misfortune". It other words, the implementation is correct according to the original design, so it won't change until there is a major revision and the design is reconsidered. Timer was one of the original Boost seed libraries. We now have a much more refined view of portability, and would do things differently if we were to do a timer-like class today. Jeff Garland and I have discussed this several times, but it just isn't bubbling up to the top of the priority list. Thanks for the report, --Beman </pre> Ticket