44 #ifndef LIB_TEST_MICROBENCHMARK_H 45 #define LIB_TEST_MICROBENCHMARK_H 63 constexpr
size_t DEFAULT_RUNS = 10
'000'000;
64 using CLOCK_SCALE = std::micro;
78 using std::chrono::steady_clock;
79 using Dur = std::chrono::duration<double, CLOCK_SCALE>;
81 auto start = steady_clock::now();
83 Dur duration = steady_clock::now () - start;
84 return duration.count() / repeatCnt;
95 benchmarkLoop (FUN
const& testSubject,
const size_t repeatCnt = DEFAULT_RUNS)
98 auto subject4benchmark = microbenchmark::adapted4benchmark (testSubject);
101 for (
size_t i=0; i<repeatCnt; ++i)
102 checksum += subject4benchmark(i);
120 volatile size_t checksum{0};
121 auto invokeTestLoop = [&]{ checksum =
benchmarkLoop (testSubject, repeatCnt); };
123 return std::make_pair (micros, checksum);
145 template<
size_t nThreads,
class FUN>
149 using std::chrono::steady_clock;
150 using Dur = std::chrono::duration<double, CLOCK_SCALE>;
153 auto subject4benchmark = microbenchmark::adapted4benchmark (subject);
154 using Subject = decltype(subject4benchmark);
161 ,[
this,loopCnt, testSubject=subject, &testStart]
165 auto start = steady_clock::now();
166 for (
size_t i=0; i < loopCnt; ++i)
167 checksum += testSubject(i);
168 duration = steady_clock::now () - start;
178 for (
size_t n=0; n<nThreads; ++n)
179 threads.
emplace (subject4benchmark, repeatCnt, testStart);
184 Dur sumDuration{0.0};
185 for (
auto& thread : threads)
188 sumDuration += thread.duration;
189 checksum += thread.checksum;
192 double micros = sumDuration.count() / (nThreads * repeatCnt);
193 return std::make_tuple (micros, checksum);
Variant of the standard case, requiring to wait and join() on the termination of this thread...
auto threadBenchmark(FUN const &subject, const size_t repeatCnt=DEFAULT_RUNS)
perform a multithreaded microbenchmark.
A fixed collection of non-copyable polymorphic objects.
TY & emplace(ARGS &&...args)
push new entry at the end of this container and build object of type TY in place there ...
Implementation namespace for support and library code.
Helpers and wrappers so simplify usage of micobenchmark.hpp.
auto microBenchmark(FUN const &testSubject, const size_t repeatCnt=DEFAULT_RUNS)
perform a simple looped microbenchmark.
Managing a collection of non-copyable polymorphic objects in compact storage.
double benchmarkTime(FUN const &invokeTestCode, const size_t repeatCnt=1)
Helper to invoke a functor or λ to observe its running time.
Metaprogramming tools for transforming functor types.
Convenience front-end to simplify and codify basic thread handling.
A one time N-fold mutual synchronisation barrier.
A thin convenience wrapper to simplify thread-handling.
size_t benchmarkLoop(FUN const &testSubject, const size_t repeatCnt=DEFAULT_RUNS)
Benchmark building block to invoke a functor or λ in a tight loop, passing the current loop index and...
A N-fold synchronisation latch using yield-wait until fulfilment.