OpenFPM  5.2.0
Project that contain the implementation of distributed structures
timer Class Reference

Class for cpu time benchmarking. More...

#include <timer.hpp>

Public Member Functions

 timer ()
 Default constructor.
 
void start ()
 Start the timer.
 
void stop ()
 Stop the timer.
 
double getwct ()
 Return the elapsed real time.
 
double getcputime ()
 Return the cpu time.
 
void reset ()
 Reset the timer.
 

Private Member Functions

void check ()
 

Private Attributes

bool running
 Flag that indicate if the timer is running or not.
 
struct timespec tsstart
 starting time
 
clock_t cstart
 start time from epoch
 
struct timespec tsstop
 
clock_t cstop
 stop time from epoch
 

Detailed Description

Class for cpu time benchmarking.

Usage:

timer t;
// start the timer
t.start();
sleep(1);
// get the elapsed real time and cpu time without stop
BOOST_REQUIRE_CLOSE(t.getwct(),1.0,20.0);
BOOST_REQUIRE_SMALL(t.getcputime(),10.0);
sleep(1);
// stop the timer
t.stop();
sleep(1);
// unusefull
t.stop();
// get the cpu time and real time
t.getcputime();
t.getwct();
// get the elapsed real time and cpu time without stop
BOOST_REQUIRE_CLOSE(t.getwct(),2.0,20.0);
BOOST_REQUIRE_SMALL(t.getcputime(),10.0);
t.reset();
BOOST_REQUIRE_CLOSE(t.getwct(),0.0,20.0);
BOOST_REQUIRE_SMALL(t.getcputime(),10.0);
Class for cpu time benchmarking.
Definition: timer.hpp:28

Definition at line 27 of file timer.hpp.


The documentation for this class was generated from the following file: