KFoundation  v2.1
A Better Foundation Library for C++
 All Classes Functions Variables Typedefs Enumerations Enumerator Groups Pages
Public Member Functions | List of all members
kfoundation::Timer Class Reference

Utility class to measure execution time of a code fragment. More...

#include <kfoundation/Timer.h>

Inheritance diagram for kfoundation::Timer:
Inheritance graph
[legend]

Public Member Functions

 Timer ()
 Default constructor.
 
 Timer (RefConst< UString > name)
 Constructor, creates a named timer.
 
void start ()
 Starts measuring.
 
bool isStarted () const
 Checks if the timer is started.
 
double getRealTime () const
 Returns the elapsed time since start() is called.
 
double get () const
 Returns amount of CPU time consumed by this process since start() is called. More...
 
void serialize (Ref< ObjectSerializer > stream) const
 Implements compatibility with SerializingStreamer interface.
 
- Public Member Functions inherited from kfoundation::KFObject
bool equals (RefConst< KFObject > other) const
 Checks if this object is the same as the one reffered by the given refrence.
 
- Public Member Functions inherited from kfoundation::SerializingStreamer
virtual RefConst< UString > toString () const
 Converts the result of invocation of printToStream(ostream&) to a std::string object.
 
virtual void printToStream (Ref< OutputStream > os) const
 Implements compatibility with Streamer interface.
 

Detailed Description

Utility class to measure execution time of a code fragment.

It keeps elapsed time and consumed CPU time. Usage:

Timer t;
t.start();
... do whatever you want to measure here ...
LOG << t << ENDS;

If you want to store the elapsed time to use it later, use get() method.

double duration = t.get();

To reset an already started timer, call start() method again.

Member Function Documentation

double kfoundation::Timer::get ( ) const

Returns amount of CPU time consumed by this process since start() is called.

This might be bigger or smaller than get() depending of the amount of CPU time and number of cores specified by OS to execute the process.


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