mCRL2
Loading...
Searching...
No Matches
mcrl2::utilities::execution_timer Class Reference

Simple timer to time the CPU time used by a piece of code. More...

#include <execution_timer.h>

Classes

struct  timing
 Pair of start and finish times. More...
 

Public Member Functions

 execution_timer (const std::string &tool_name="", std::string const &filename="")
 Constructor of a simple execution timer.
 
 ~execution_timer ()
 Destructor.
 
void start (const std::string &timing_name)
 Start measurement with a hint.
 
void finish (const std::string &timing_name)
 Finish a measurement with a hint.
 
void report ()
 Write all timing information that has been recorded.
 

Protected Member Functions

void write_report (std::ostream &s)
 Write the report to an output stream.
 

Protected Attributes

std::string m_tool_name
 name of the tool we are timing
 
std::string m_filename
 name of the file to write timings to
 
std::map< std::string, timingm_timings
 collection of timings
 

Detailed Description

Simple timer to time the CPU time used by a piece of code.

Example usage: execution_timer timer("test_tool", "/path/to/file") timer.start("hint") ... (execute some code here) ... timer.finish("hint") timer.report()

This will output the following to the file "/path/to/file", or standard error if filename is empty, assuming that the time between start and finish is n seconds (with precision of 2 decimal places).

  • tool: test_tool timing: hint: n

Note that this is an output format that can immediately be parsed using YAML (http://www.yaml.org/)

Definition at line 46 of file execution_timer.h.

Constructor & Destructor Documentation

◆ execution_timer()

mcrl2::utilities::execution_timer::execution_timer ( const std::string &  tool_name = "",
std::string const &  filename = "" 
)
inline

Constructor of a simple execution timer.

Parameters
[in]tool_nameName of the tool that does the measurements
[in]filenameName of the file to which the measurements are written

Definition at line 105 of file execution_timer.h.

◆ ~execution_timer()

mcrl2::utilities::execution_timer::~execution_timer ( )
inline

Destructor.

Definition at line 111 of file execution_timer.h.

Member Function Documentation

◆ finish()

void mcrl2::utilities::execution_timer::finish ( const std::string &  timing_name)
inline

Finish a measurement with a hint.

Parameters
[in]timing_nameName of the measurment being finished
Precondition
A start(timing_name) was executed before
Postcondition
The current time has been recorded as end time of timing_name

Definition at line 135 of file execution_timer.h.

◆ report()

void mcrl2::utilities::execution_timer::report ( )
inline

Write all timing information that has been recorded.

Timing information is written to the filename that was provided in the constructor. If no filename was provided (i.e. the filename is empty) the information is written to standard error. The output is in YAML compatible format.

Definition at line 158 of file execution_timer.h.

◆ start()

void mcrl2::utilities::execution_timer::start ( const std::string &  timing_name)
inline

Start measurement with a hint.

Parameters
[in]timing_nameName of the measurement being started
Precondition
No start(timing_name) has occurred before
Postcondition
The current time has been recorded as starting time of timing_name

Definition at line 118 of file execution_timer.h.

◆ write_report()

void mcrl2::utilities::execution_timer::write_report ( std::ostream &  s)
inlineprotected

Write the report to an output stream.

Parameters
[in]sThe output stream to which the report is written.

Definition at line 71 of file execution_timer.h.

Member Data Documentation

◆ m_filename

std::string mcrl2::utilities::execution_timer::m_filename
protected

name of the file to write timings to

Definition at line 66 of file execution_timer.h.

◆ m_timings

std::map<std::string, timing> mcrl2::utilities::execution_timer::m_timings
protected

collection of timings

Definition at line 67 of file execution_timer.h.

◆ m_tool_name

std::string mcrl2::utilities::execution_timer::m_tool_name
protected

name of the tool we are timing

Definition at line 65 of file execution_timer.h.


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