tracktion-engine 3.0-10-g034fdde4aa5
Tracktion Engine — High level data model for audio applications

« « « Anklang Documentation
Loading...
Searching...
No Matches
tracktion_Benchmark.h
Go to the documentation of this file.
1 /*
2 ,--. ,--. ,--. ,--.
3 ,-' '-.,--.--.,--,--.,---.| |,-.,-' '-.`--' ,---. ,--,--, Copyright 2024
4 '-. .-'| .--' ,-. | .--'| /'-. .-',--.| .-. || \ Tracktion Software
5 | | | | \ '-' \ `--.| \ \ | | | |' '-' '| || | Corporation
6 `---' `--' `--`--'`---'`--'`--' `---' `--' `---' `--''--' www.tracktion.com
7
8 Tracktion Engine uses a GPL/commercial licence - see LICENCE.md for details.
9*/
10
11#pragma once
12
13#include "../../tracktion_graph/utilities/tracktion_PerformanceMeasurement.h"
14
15namespace tracktion { inline namespace engine
16{
17
18//==============================================================================
19//==============================================================================
31
34{
35 return { std::hash<std::string>{} (name + description),
36 category, name, description };
37}
38
39//==============================================================================
42{
44 double totalSeconds = 0.0, meanSeconds = 0.0, minSeconds = 0.0, maxSeconds = 0.0, varianceSeconds = 0.0;
45 uint64_t totalCycles = 0, meanCycles = 0, minCycles = 0, maxCycles = 0;
46 double varianceCycles = 0.0;
48};
49
53{
54 return { description,
55 stats.totalSeconds, stats.meanSeconds, stats.minimumSeconds, stats.maximumSeconds, stats.getVarianceSeconds(),
56 stats.totalCycles, (uint64_t) stats.meanCycles, stats.minimumCycles, stats.maximumCycles, stats.getVarianceCycles() };
57}
58
59//==============================================================================
69{
70public:
73 : description (std::move (desc))
74 {
75 }
76
78 void start()
79 {
80 measurement.start();
81 }
82
84 void stop()
85 {
86 measurement.stop();
87 }
88
91 {
92 return createBenchmarkResult (description, measurement.getStatistics());
93 }
94
95private:
96 BenchmarkDescription description;
97 tracktion::graph::PerformanceMeasurement measurement { {}, -1, false };
98};
99
100//==============================================================================
110{
111public:
113 BenchmarkList() = default;
114
117 {
118 std::lock_guard lock (mutex);
119 results.emplace_back (std::move (r));
120 }
121
124 {
125 std::lock_guard lock (mutex);
126 return results;
127 }
128
130 void clear()
131 {
132 std::lock_guard lock (mutex);
133 return results.clear();
134 }
135
138 {
139 static BenchmarkList list;
140 return list;
141 }
142
143private:
144 mutable std::mutex mutex;
146};
147
148//==============================================================================
161{
164 : benchmark (std::move (desc))
165 {
166 benchmark.start();
167 }
168
171 {
172 benchmark.stop();
174 }
175
176private:
177 Benchmark benchmark;
178};
179
180//==============================================================================
185{
188 : benchmark (bm)
189 {
190 benchmark.start();
191 }
192
195 {
196 benchmark.stop();
197 }
198
199private:
200 Benchmark& benchmark;
201};
202
203}} // namespace tracktion { inline namespace engine
static String getOperatingSystemName()
static Time JUCE_CALLTYPE getCurrentTime() noexcept
Contans a list of BenchmarkResult[s].
void clear()
Removes all the current results.
static BenchmarkList & getInstance()
Gets the singleton instance.
void addResult(BenchmarkResult r)
Adds a result to the list.
std::vector< BenchmarkResult > getResults() const
Returns all the results.
BenchmarkList()=default
Constructs a BenchmarkList.
An indiviual Benchmark.
BenchmarkResult getResult() const
Returns the timing results.
void stop()
Stops timing the benchmark.
Benchmark(BenchmarkDescription desc)
Creates a Benchmark for a given BenchmarkDescription.
void start()
Starts timing the benchmark.
A timer for measuring performance of code.
bool stop()
Stops timing and prints out the results.
Statistics getStatistics() const
Returns a copy of the current stats.
std::string category
A category for grouping.
size_t hash
A hash uniquely identifying this benchmark.
std::string name
A human-readable name for the benchmark.
std::string platform
A platform string.
BenchmarkDescription description
The BenchmarkDescription.
BenchmarkDescription createBenchmarkDescription(std::string category, std::string name, std::string description)
Creates a description by hashing the name and description fields.
std::string description
An optional description that might include configs etc.
BenchmarkResult createBenchmarkResult(BenchmarkDescription description, const tracktion::graph::PerformanceMeasurement::Statistics &stats)
Creates a BenchmarkResult from a set of Statistics.
Holds the duration a benchmark took to run.
typedef uint64_t
Helper class for measuring a benchmark and adding it to the singleton BenchmarkList list.
~ScopedBenchmark()
Stops the Benchmark and adds the result to the BenchmarkList.
ScopedBenchmark(BenchmarkDescription desc)
Constructs and starts a Benchmark.
Helper class for starting/stopping a benchmark measurement.
ScopedMeasurement(Benchmark &bm)
Constructs and starts a Benchmark.