SourcePro® API Reference Guide

 
Loading...
Searching...
No Matches
RWClockTimer Struct Reference

Measures elapsed wall clock time. More...

#include <rw/timer.h>

Public Member Functions

 RWClockTimer ()
 
rwint64 elapsedMicroseconds () const
 
rwint64 elapsedMilliseconds () const
 
rwint64 elapsedSeconds () const
 
double elapsedTime () const
 
void reset ()
 
void start ()
 
void stop ()
 

Detailed Description

This class measures elapsed wall clock 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().

Synopsis
#include <rw/timer.h>
Measures elapsed wall clock time.
Definition timer.h:247
Persistence
None
Example
#include <iostream>
#include <rw/timer.h>
#include <rw/tools/datetime.h>
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 << "Wall : "
<< double(t.elapsedMicroseconds()) / 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 elapsedMicroseconds() const

Constructor & Destructor Documentation

◆ RWClockTimer()

RWClockTimer::RWClockTimer ( )

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

Member Function Documentation

◆ elapsedMicroseconds()

rwint64 RWClockTimer::elapsedMicroseconds ( ) const

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

◆ elapsedMilliseconds()

rwint64 RWClockTimer::elapsedMilliseconds ( ) const

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

◆ elapsedSeconds()

rwint64 RWClockTimer::elapsedSeconds ( ) const

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

◆ elapsedTime()

double RWClockTimer::elapsedTime ( ) const

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

◆ reset()

void RWClockTimer::reset ( )

Resets (and stops) the timer.

◆ start()

void RWClockTimer::start ( )

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

◆ stop()

void RWClockTimer::stop ( )

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

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