TracktionEngine
Classes | Public Member Functions | List of all members
tracktion::graph::PerformanceMeasurement Class Reference

A timer for measuring performance of code. More...

Classes

struct  Statistics
 Holds the current statistics. More...
 

Public Member Functions

 PerformanceMeasurement (const std::string &counterName, int runsPerPrintout=100, bool printOnDestruction=true)
 Creates a PerformanceMeasurement object. More...
 
 ~PerformanceMeasurement ()
 Destructor. More...
 
void start () noexcept
 Starts timing. More...
 
bool stop ()
 Stops timing and prints out the results. More...
 
void printStatistics ()
 Dumps the current metrics to std::cout. More...
 
Statistics getStatistics () const
 Returns a copy of the current stats. More...
 
Statistics getStatisticsAndReset ()
 Returns a copy of the current stats, and resets the internal counter. More...
 

Detailed Description

A timer for measuring performance of code.

e.g.

PerformanceMeasurement pc ("fish", 50);
for (;;)
{
const ScopedPerformanceMeasurement (pc);
doSomethingFishy();
}
PerformanceMeasurement(const std::string &counterName, int runsPerPrintout=100, bool printOnDestruction=true)
Creates a PerformanceMeasurement object.
Definition: tracktion_PerformanceMeasurement.h:202

In this example, the time of each period between calling start/stop will be measured and averaged over 50 runs, and the results logged to std::cout every 50 times round the loop.

Constructor & Destructor Documentation

◆ PerformanceMeasurement()

tracktion::graph::PerformanceMeasurement::PerformanceMeasurement ( const std::string &  counterName,
int  runsPerPrintout = 100,
bool  printOnDestruction = true 
)

Creates a PerformanceMeasurement object.

Parameters
counterNamethe name used when printing out the statistics
runsPerPrintoutthe number of start/stop iterations before calling printStatistics()

References tracktion::graph::PerformanceMeasurement::Statistics::name.

◆ ~PerformanceMeasurement()

tracktion::graph::PerformanceMeasurement::~PerformanceMeasurement ( )

Member Function Documentation

◆ start()

void tracktion::graph::PerformanceMeasurement::start ( )
noexcept

Starts timing.

See also
stop

◆ stop()

bool tracktion::graph::PerformanceMeasurement::stop ( )

Stops timing and prints out the results.

The number of iterations before doing a printout of the results is set in the constructor.

See also
start

References tracktion::graph::PerformanceMeasurement::Statistics::addResult(), tracktion::graph::PerformanceMeasurement::Statistics::numRuns, and printStatistics().

◆ printStatistics()

void tracktion::graph::PerformanceMeasurement::printStatistics ( )

Dumps the current metrics to std::cout.

References getStatisticsAndReset(), and tracktion::graph::PerformanceMeasurement::Statistics::toString().

Referenced by stop(), and ~PerformanceMeasurement().

◆ getStatistics()

PerformanceMeasurement::Statistics tracktion::graph::PerformanceMeasurement::getStatistics ( ) const

Returns a copy of the current stats.

◆ getStatisticsAndReset()

PerformanceMeasurement::Statistics tracktion::graph::PerformanceMeasurement::getStatisticsAndReset ( )

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