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, {__VA_ARGS__}}, zeroerr::TestType::bench); \
21 static void function(ZEROERR_UNUSED(zeroerr::TestContext* _ZEROERR_TEST_CONTEXT))
23#define BENCHMARK(...) \
24 ZEROERR_SUPPRESS_VARIADIC_MACRO \
25 ZEROERR_CREATE_BENCHMARK_FUNC(ZEROERR_NAMEGEN(_zeroerr_benchmark), __VA_ARGS__) \
26 ZEROERR_SUPPRESS_VARIADIC_MACRO_POP \
48using Clock = std::conditional<std::chrono::high_resolution_clock::is_steady,
49 std::chrono::high_resolution_clock, std::chrono::steady_clock>::type;
52struct LinuxPerformanceCounter;
53struct WindowsPerformanceCounter;
79 detail::LinuxPerformanceCounter*
_perf =
nullptr;
80 detail::WindowsPerformanceCounter*
win_perf =
nullptr;
131 using ns = std::chrono::nanoseconds;
132 using ms = std::chrono::milliseconds;
143 template <
typename Op>
149 while (n-- > 0) op();
157 template <
typename Op>
159 return run(
"", std::forward<Op>(op));
170void doNotOptimizeAwaySink(
const void*);
174 doNotOptimizeAwaySink(&val);
186 asm volatile(
"" : :
"r,m"(val) :
"memory");
191#if defined(__clang__)
193 asm volatile(
"" :
"+r,m"(val) : :
"memory");
196 asm volatile(
"" :
"+m,r"(val) : :
"memory");
210template <
typename Arg>
#define ZEROERR_SUPPRESS_COMMON_WARNINGS_POP
Definition config.h:268
#define ZEROERR_SUPPRESS_COMMON_WARNINGS_PUSH
Definition config.h:220
void doNotOptimizeAway(const T &val)
Definition benchmark.h:184
Definition benchmark.cpp:17
void doNotOptimizeAway(Arg &&arg)
Makes sure none of the given arguments are optimized away by the compiler.
Definition benchmark.h:211
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:49
size_t getNumIter(BenchState *state)
Definition benchmark.cpp:154
BenchResult is a result of running the benchmark.
Definition benchmark.h:86
Measure
Definition benchmark.h:87
@ all
Definition benchmark.h:96
@ iterations
Definition benchmark.h:89
@ branch_misses
Definition benchmark.h:95
@ context_switches
Definition benchmark.h:92
@ instructions
Definition benchmark.h:93
@ time_elapsed
Definition benchmark.h:88
@ branch_instructions
Definition benchmark.h:94
@ cpu_cycles
Definition benchmark.h:91
@ page_faults
Definition benchmark.h:90
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:98
PerfCountSet< bool > has
Definition benchmark.h:100
std::vector< PerfCountSet< double > > epoch_details
Definition benchmark.h:99
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:123
uint64_t iter_per_epoch
Definition benchmark.h:129
std::chrono::milliseconds ms
Definition benchmark.h:132
const char * time_unit
Definition benchmark.h:126
Benchmark & run(std::string name, Op &&op)
Definition benchmark.h:144
std::vector< BenchResult > result
Definition benchmark.h:162
uint64_t warmup
Definition benchmark.h:128
uint64_t minimalResolutionMutipler
Definition benchmark.h:138
Benchmark & run(Op &&op)
Definition benchmark.h:158
time mMaxEpochTime
Definition benchmark.h:135
std::chrono::nanoseconds ns
Definition benchmark.h:131
ns time
Definition benchmark.h:133
time mMinEpochTime
Definition benchmark.h:136
Benchmark(std::string title)
Definition benchmark.h:140
uint64_t epochs
Definition benchmark.h:127
void report()
Definition benchmark.cpp:235
std::string title
Definition benchmark.h:124
const char * op_unit
Definition benchmark.h:125
PerfCountSet is a set of performance counters.
Definition benchmark.h:35
T iterations
Definition benchmark.h:36
T & timeElapsed()
Definition benchmark.h:39
T & branchInstructions()
Definition benchmark.h:44
T & pageFaults()
Definition benchmark.h:40
T & cpuCycles()
Definition benchmark.h:41
T data[7]
Definition benchmark.h:37
T & contextSwitches()
Definition benchmark.h:42
T & branchMisses()
Definition benchmark.h:45
T & instructions()
Definition benchmark.h:43