TracktionEngine
Loading...
Searching...
No Matches
graph::PerformanceMeasurement Class Reference

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

#include <tracktion_PerformanceMeasurement.h>

Classes

struct  Statistics
 Holds the current statistics. More...

Public Member Functions

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

Detailed Description

A timer for measuring performance of code.

e.g.

PerformanceMeasurement pc ("fish", 50);
for (;;)
{
doSomethingFishy();
}
PerformanceMeasurement(std::string counterName, int runsPerPrintout=100, bool printOnDestruction=true)
Creates a PerformanceMeasurement object.
Definition tracktion_PerformanceMeasurement.h:254
RAII wrapper to start and stop a performance measurement.
Definition tracktion_PerformanceMeasurement.h:220

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()

graph::PerformanceMeasurement::PerformanceMeasurement ( 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 PerformanceMeasurement().

Referenced by PerformanceMeasurement().

◆ ~PerformanceMeasurement()

graph::PerformanceMeasurement::~PerformanceMeasurement ( )

Destructor.

References printStatistics().

Member Function Documentation

◆ start()

void graph::PerformanceMeasurement::start ( )
noexcept

Starts timing.

See also
stop

◆ stop()

bool 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 printStatistics().

◆ printStatistics()

void graph::PerformanceMeasurement::printStatistics ( )

Dumps the current metrics to std::cout.

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

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

◆ getName()

std::string graph::PerformanceMeasurement::getName ( ) const

Returns the name.

◆ getStatistics()

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

Returns a copy of the current stats.

◆ getStatisticsAndReset()

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

Returns a copy of the current stats, and resets the internal counter.

Referenced by printStatistics().


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