17 #define ZEROERR_CREATE_BENCHMARK_FUNC(function, name) \
18 static void function(zeroerr::TestContext*); \
19 static zeroerr::detail::regTest ZEROERR_NAMEGEN(_zeroerr_reg)( \
20 {name, __FILE__, __LINE__, function}, zeroerr::TestType::bench); \
21 static void function(ZEROERR_UNUSED(zeroerr::TestContext* _ZEROERR_TEST_CONTEXT))
23 #define BENCHMARK(name) ZEROERR_CREATE_BENCHMARK_FUNC(ZEROERR_NAMEGEN(_zeroerr_benchmark), name)
45 using Clock = std::conditional<std::chrono::high_resolution_clock::is_steady,
46 std::chrono::high_resolution_clock, std::chrono::steady_clock>::type;
49 struct LinuxPerformanceCounter;
50 struct WindowsPerformanceCounter;
76 detail::LinuxPerformanceCounter*
_perf =
nullptr;
77 detail::WindowsPerformanceCounter*
win_perf =
nullptr;
128 using ns = std::chrono::nanoseconds;
129 using ms = std::chrono::milliseconds;
140 template <
typename Op>
146 while (n-- > 0) op();
154 template <
typename Op>
156 return run(
"", std::forward<Op>(op));
166 #if defined(_MSC_VER)
167 void doNotOptimizeAwaySink(
void const*);
169 template <
typename T>
171 doNotOptimizeAwaySink(&val);
180 template <
typename T>
183 asm volatile(
"" : :
"r,m"(val) :
"memory");
186 template <
typename T>
188 #if defined(__clang__)
190 asm volatile(
"" :
"+r,m"(val) : :
"memory");
193 asm volatile(
"" :
"+m,r"(val) : :
"memory");
207 template <
typename Arg>
#define ZEROERR_SUPPRESS_COMMON_WARNINGS_POP
Definition: config.h:265
#define ZEROERR_SUPPRESS_COMMON_WARNINGS_PUSH
Definition: config.h:218
void doNotOptimizeAway(T const &val)
Definition: benchmark.h:181
Definition: benchmark.cpp:17
void doNotOptimizeAway(Arg &&arg)
Makes sure none of the given arguments are optimized away by the compiler.
Definition: benchmark.h:208
void destroyBenchState(BenchState *state)
Definition: benchmark.cpp:152
void moveResult(BenchState *state, std::string name)
Definition: benchmark.cpp:179
BenchState * createBenchState(Benchmark &benchmark)
Definition: benchmark.cpp:151
void runIteration(BenchState *state)
Definition: benchmark.cpp:159
std::conditional< std::chrono::high_resolution_clock::is_steady, std::chrono::high_resolution_clock, std::chrono::steady_clock >::type Clock
Definition: benchmark.h:46
size_t getNumIter(BenchState *state)
Definition: benchmark.cpp:154
BenchResult is a result of running the benchmark.
Definition: benchmark.h:83
Measure
Definition: benchmark.h:84
@ all
Definition: benchmark.h:93
@ iterations
Definition: benchmark.h:86
@ branch_misses
Definition: benchmark.h:92
@ context_switches
Definition: benchmark.h:89
@ instructions
Definition: benchmark.h:90
@ time_elapsed
Definition: benchmark.h:85
@ branch_instructions
Definition: benchmark.h:91
@ cpu_cycles
Definition: benchmark.h:88
@ page_faults
Definition: benchmark.h:87
PerfCountSet< double > mean() const
Definition: benchmark.cpp:229
PerfCountSet< double > average() const
Definition: benchmark.cpp:189
PerfCountSet< double > max() const
Definition: benchmark.cpp:216
PerfCountSet< double > min() const
Definition: benchmark.cpp:203
std::string name
Definition: benchmark.h:95
PerfCountSet< bool > has
Definition: benchmark.h:97
std::vector< PerfCountSet< double > > epoch_details
Definition: benchmark.h:96
Definition: benchmark.cpp:50
Benchmark create a core object for configuration of a benchmark. This class is a driver to run multip...
Definition: benchmark.h:120
uint64_t iter_per_epoch
Definition: benchmark.h:126
std::chrono::milliseconds ms
Definition: benchmark.h:129
const char * time_unit
Definition: benchmark.h:123
std::vector< BenchResult > result
Definition: benchmark.h:159
uint64_t warmup
Definition: benchmark.h:125
uint64_t minimalResolutionMutipler
Definition: benchmark.h:135
time mMaxEpochTime
Definition: benchmark.h:132
std::chrono::nanoseconds ns
Definition: benchmark.h:128
ns time
Definition: benchmark.h:130
Benchmark & run(Op &&op)
Definition: benchmark.h:155
time mMinEpochTime
Definition: benchmark.h:133
Benchmark(std::string title)
Definition: benchmark.h:137
uint64_t epochs
Definition: benchmark.h:124
void report()
Definition: benchmark.cpp:235
std::string title
Definition: benchmark.h:121
Benchmark & run(std::string name, Op &&op)
Definition: benchmark.h:141
const char * op_unit
Definition: benchmark.h:122
PerfCountSet is a set of performance counters.
Definition: benchmark.h:32
T iterations
Definition: benchmark.h:33
T & timeElapsed()
Definition: benchmark.h:36
T & branchMisses()
Definition: benchmark.h:42
T & pageFaults()
Definition: benchmark.h:37
T & branchInstructions()
Definition: benchmark.h:41
T data[7]
Definition: benchmark.h:34
T & instructions()
Definition: benchmark.h:40
T & cpuCycles()
Definition: benchmark.h:38
T & contextSwitches()
Definition: benchmark.h:39