SourcePro® API Reference Guide

 
Loading...
Searching...
No Matches

Measures two types of time, system and user time, both of which can be reported as cumulative if desired. More...

#include <rw/timer.h>

Public Types

enum  Type { USER , SYSTEM , userTime , systemTime }
 

Public Member Functions

 RWTimer ()
 
rwint64 elapsedMicroseconds () const
 
rwint64 elapsedMilliseconds () const
 
rwint64 elapsedSeconds () const
 
double elapsedTime () const
 
void reset ()
 
void start ()
 
void stop ()
 
rwint64 time (int=userTime|systemTime) const
 

Detailed Description

This class can measure two types of time: system time and user time, both of which can be reported as cumulative, if desired. 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 different APIs on Windows and UNIX; on Windows it uses GetProcessTime, whereas on UNIX it uses the getrusage system call.

The time intervals are stored inside the RWTimer objects as 64-bit integers. The resolution of the timer is microseconds. The wrap-up interval for the counters is > 500,000 years.

Synopsis
#include <rw/timer.h>
RWTimer timer;
Measures two types of time, system and user time, both of which can be reported as cumulative if desi...
Definition timer.h:89
Persistence
None
Example
#include <rw/timer.h>
#include <rw/tools/datetime.h>
#include <iostream>
int main() {
std::cout << "Starting the timer ...\n";
std::cout << "... and looping for 5 seconds "
"using RWDateTime as clock ...\n";
t.start(); // Start the timer
// Loop for 5 seconds:
for (; (RWDateTime::now() - tmp) < 5000;) {
}
t.stop(); // Stop the timer
std::cout << "The elapsed time was: \n";
std::cout << "System : "
<< double(t.time(RWTimer::systemTime)) / 1000000.0F
<< " seconds.\n";
std::cout << "User : "
<< double(t.time(RWTimer::userTime)) / 1000000.0F
<< " seconds.\n";
std::cout << "Total : "
1000000.0F
<< " seconds.\n";
return 0;
}
Represents a date and time stored in milliseconds.
Definition tools/datetime.h:219
static RWDateTime now()
Definition tools/datetime.h:1545
@ setCurrentTime
Definition tools/datetime.h:241
rwint64 time(int=userTime|systemTime) const
void stop()
@ userTime
Definition timer.h:115
@ systemTime
Definition timer.h:120
void start()

Member Enumeration Documentation

◆ Type

The Type type indicates the type of time returned by the time() member function.

Enumerator
USER 
Deprecated
As of SourcePro 11, use RWTimer::userTime instead.
SYSTEM 
Deprecated
As of SourcePro 11, use RWTimer::systemTime instead.
userTime 

Cumulated user time

systemTime 

Cumulated system time

Constructor & Destructor Documentation

◆ RWTimer()

RWTimer::RWTimer ( )
inline

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

Member Function Documentation

◆ elapsedMicroseconds()

rwint64 RWTimer::elapsedMicroseconds ( ) const

Returns the number of microseconds that have elapsed while the timer was in the running state.

◆ elapsedMilliseconds()

rwint64 RWTimer::elapsedMilliseconds ( ) const

Returns the number of milliseconds that have elapsed while the timer was in the running state.

◆ elapsedSeconds()

rwint64 RWTimer::elapsedSeconds ( ) const

Returns the number of seconds that have elapsed while the timer was in the running state.

◆ elapsedTime()

double RWTimer::elapsedTime ( ) const

Returns the amount of user and system time, in seconds, that has accumulated while the timer was in the running state.

◆ reset()

void RWTimer::reset ( )
inline

Resets (and stops) the timer.

◆ start()

void RWTimer::start ( )

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

◆ stop()

void RWTimer::stop ( )

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

◆ time()

rwint64 RWTimer::time ( int = userTime|systemTime) const

Returns the amount of time, in microseconds, measured by the object. The parameter is an integer bitmask indicating the type of time requested.

Copyright © 2024 Rogue Wave Software, Inc., a Perforce company. All Rights Reserved.