RWTimer(3C++)

RWTimer - Rogue Wave library class

As shipped in IRIX 6.5.15. Unchanged since IRIX 6.5.

Name
     RWTimer - Rogue Wave library class

Synopsis
              #include <rw/timer.h>



              RWTimer timer;




Description
     This class can measure elapsed CPU (user) time.  The timer has two
     states: running and stopped.  The timer measures the total amount of time
     spent in the "running" state since it was either constructed or reset.
     The timer is put into the "running" state by calling member function
     start().  It is put into the "stopped" state by calling stop(). RWTimer
     uses the system-dpendent function clock() which returns the number of
     "ticks" since it was first called.  As a result, RWTimer will not be able
     to measure intervals longer than some system-dependent value.  (For
     instance, on several common UNIX systems, this value is just under 36
     minutes.)

Persistence
     None

Example
     This example prints out the amount of CPU time used while looping for 5
     seconds (as measured using class RWTime).

              #include <rw/timer.h>



              #include <rw/rwtime.h>
          #include <rw/rstream.h>
          main()
          {RWTimer t;
           t.start();                 // Start the timer
           RWTime start;
           start.now();               // Record starting time
           // Loop for 5 seconds:
           for (RWTime current; current.seconds() - start.seconds() < 5;
                current = RWTime::now())
           {;}
           t.stop();                  // Stop the timer
           cout << t.elapsedTime() << endl;
           return 0;
          }
     Program output (exact value may differ):

              5.054945



Public Constructor




              RWTimer();


     Constructs a new timer.  The timer will not start running until start()
     is called.

Public Member Functions
              double
          elapsedTime() const;


     Returns the amount of (CPU) time that has accumulated while the timer was
     in the running state.

              void
          reset();


     Resets (and stops) the timer.

              void
          start();


     Puts the timer in the "running" state.  Time accumulates while in this
     state.

              void
          stop();


     Puts the timer in the "stopped" state.  Time will not accumulate while in
     this state.