Re: [Boost-bugs] [Boost C++ Libraries] #680: significantly different timer class behaviour on Win and Lin

Subject: Re: [Boost-bugs] [Boost C++ Libraries] #680: significantly different timer class behaviour on Win and Lin
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2007-08-28 00:17:08


#680: significantly different timer class behaviour on Win and Lin
------------------------+---------------------------------------------------
  Reporter: skv | Owner: bemandawes
      Type: Bugs | Status: closed
 Milestone: | Component: timer
   Version: None | Severity: Showstopper
Resolution: duplicate | Keywords:
------------------------+---------------------------------------------------
Changes (by bemandawes):

  * status: new => closed
  * resolution: None => duplicate

Old 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
>

> }}}

New 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


 }}}

Comment:

 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

--
Ticket URL: <http://svn.boost.org/trac/boost/ticket/680#comment:3>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.


This archive was generated by hypermail 2.1.7 : 2017-02-16 18:49:56 UTC