Opened 16 years ago
Closed 15 years ago
#680 closed Bugs (duplicate)
significantly different timer class behaviour on Win and Lin — at Version 3
Reported by: | skv | Owned by: | Beman Dawes |
---|---|---|---|
Milestone: | Component: | timer | |
Version: | None | Severity: | Showstopper |
Keywords: | Cc: |
Description (last modified by )
clock() function used in implementation of boost::timer behaves differently on Windows (MS XP Pro, MSVC 7.1) and Linux (FC3, gcc 3.4.2). Windows: clock measures elapsed time (wall clock). And this comply with boost::timer interface description. Example: boost::timer t; double sec = 1; ::Sleep(sec*1000); double d = t.elapsed(); assert(abs(d-sec) < 0.1); Linux: clock() function returnes process CPU time. The above code will fail. This difference makes boost::timer a bad candidate for cross-platform development. I can propose alternative implementation with simalar right behaviour. ------------------------------------------ #ifndef _Timer_h_dlfkgh9384ytdflg9045uhy0823475mgd385uyn0v68uy c0n4c5 #define _Timer_h_dlfkgh9384ytdflg9045uhy0823475mgd385uyn0v68uy c0n4c5 #include <time.h> namespace Timer { /* Measures intervals of wall clock time, but not process CPU time. Resolution & accuracy depends on time function abilities. */ class timer { public: // setup reference time point timer() { restart(); } // reset reference time point void restart() { ::time(&m_ref_time); } // report difference between current time and reference point double elapsed() const { time_t curr_time; ::time(&curr_time); double diff = difftime (curr_time, m_ref_time); return diff; } // forbidden private: timer(const timer &); timer & operator=(const timer &); private: time_t m_ref_time; }; } // namespace Timer #endif //_Timer_h_dlfkgh9384ytdflg9045uhy0823475mgd385 uyn0v68uyc0n4c5
Change History (3)
comment:2 by , 15 years ago
Owner: | changed from | to
---|---|
Severity: | → Showstopper |
Status: | assigned → new |
assigning to actual user "bemandawes" instead of unknown user "beman_dawes"
comment:3 by , 15 years ago
Description: | modified (diff) |
---|---|
Resolution: | None → duplicate |
Status: | new → closed |
This request has been repeated many times. The Boost.System replacement that Philippe spoke of is now (27 Aut 2007) in the boost-sandbox. See boost-root/libs/system/doc/timer.html.
This should be moving into the review queue in the next week or so. I'm closing out the ticket.
Thanks,
--Beman
Note:
See TracTickets
for help on using tickets.