Opened 16 years ago
Last modified 15 years ago
#680 closed Bugs (duplicate)
significantly different timer class behaviour on Win and Lin — at Initial Version
| Reported by: | skv | Owned by: | beman_dawes |
|---|---|---|---|
| Milestone: | Component: | timer | |
| Version: | None | Severity: | Showstopper |
| Keywords: | Cc: |
Description
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
Note:
See TracTickets
for help on using tickets.
