JUCE  v6.1.6 (6.0.8-1114)
JUCE API
Looking for a senior C++ dev?
I'm looking for work. Hire me!
juce::PerformanceCounter Class Reference

A timer for measuring performance of code and dumping the results to a file. More...

#include <juce_PerformanceCounter.h>

Collaboration diagram for juce::PerformanceCounter:

Classes

struct  Statistics
 Holds the current statistics. More...
 

Public Member Functions

 PerformanceCounter (const String &counterName, int runsPerPrintout=100, const File &loggingFile=File())
 Creates a PerformanceCounter object. More...
 
 ~PerformanceCounter ()
 Destructor. More...
 
Statistics getStatisticsAndReset ()
 Returns a copy of the current stats, and resets the internal counter. More...
 
void printStatistics ()
 Dumps the current metrics to the debugger output and to a file. More...
 
void start () noexcept
 Starts timing. More...
 
bool stop ()
 Stops timing and prints out the results. More...
 

Private Attributes

File outputFile
 
int64 runsPerPrint
 
int64 startTime
 
Statistics stats
 

Detailed Description

A timer for measuring performance of code and dumping the results to a file.

e.g.

PerformanceCounter pc ("fish", 50, "/temp/myfishlog.txt");
for (;;)
{
pc.start();
doSomethingFishy();
pc.stop();
}

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

@tags{Core}

Constructor & Destructor Documentation

◆ PerformanceCounter()

juce::PerformanceCounter::PerformanceCounter ( const String counterName,
int  runsPerPrintout = 100,
const File loggingFile = File() 
)

Creates a PerformanceCounter object.

Parameters
counterNamethe name used when printing out the statistics
runsPerPrintoutthe number of start/stop iterations before calling printStatistics()
loggingFilea file to dump the results to - if this is File(), the results are just written to the debugger output

◆ ~PerformanceCounter()

juce::PerformanceCounter::~PerformanceCounter ( )

Destructor.

Member Function Documentation

◆ getStatisticsAndReset()

Statistics juce::PerformanceCounter::getStatisticsAndReset ( )

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

◆ printStatistics()

void juce::PerformanceCounter::printStatistics ( )

Dumps the current metrics to the debugger output and to a file.

As well as using Logger::outputDebugString to print the results, this will write then to the file specified in the constructor (if this was valid).

◆ start()

void juce::PerformanceCounter::start ( )
noexcept

Starts timing.

See also
stop

◆ stop()

bool juce::PerformanceCounter::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

Member Data Documentation

◆ outputFile

File juce::PerformanceCounter::outputFile
private

◆ runsPerPrint

int64 juce::PerformanceCounter::runsPerPrint
private

◆ startTime

int64 juce::PerformanceCounter::startTime
private

◆ stats

Statistics juce::PerformanceCounter::stats
private

The documentation for this class was generated from the following file:
juce::PerformanceCounter::PerformanceCounter
PerformanceCounter(const String &counterName, int runsPerPrintout=100, const File &loggingFile=File())
Creates a PerformanceCounter object.