53 #ifndef LIB_TEST_MICROBENCHMARK_H 54 #define LIB_TEST_MICROBENCHMARK_H 72 constexpr
size_t DEFAULT_RUNS = 10
'000'000;
73 using CLOCK_SCALE = std::micro;
87 using std::chrono::steady_clock;
88 using Dur = std::chrono::duration<double, CLOCK_SCALE>;
90 auto start = steady_clock::now();
92 Dur duration = steady_clock::now () - start;
93 return duration.count() / repeatCnt;
104 benchmarkLoop (FUN
const& testSubject,
const size_t repeatCnt = DEFAULT_RUNS)
107 auto subject4benchmark = microbenchmark::adapted4benchmark (testSubject);
110 for (
size_t i=0; i<repeatCnt; ++i)
111 checksum += subject4benchmark(i);
129 volatile size_t checksum{0};
130 auto invokeTestLoop = [&]{ checksum =
benchmarkLoop (testSubject, repeatCnt); };
132 return std::make_pair (micros, checksum);
154 template<
size_t nThreads,
class FUN>
158 using std::chrono::steady_clock;
159 using Dur = std::chrono::duration<double, CLOCK_SCALE>;
162 auto subject4benchmark = microbenchmark::adapted4benchmark (subject);
163 using Subject = decltype(subject4benchmark);
173 auto start = steady_clock::now();
174 for (
size_t i=0; i < loopCnt; ++i)
175 checksum += testSubject(i);
176 duration = steady_clock::now () - start;
186 for (
size_t n=0; n<nThreads; ++n)
187 threads.
emplace (subject4benchmark, repeatCnt, testStart);
192 Dur sumDuration{0.0};
193 for (
auto& thread : threads)
196 sumDuration += thread.duration;
197 checksum += thread.checksum;
200 double micros = sumDuration.count() / (nThreads * repeatCnt);
201 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.