MCPcopy Create free account
hub / github.com/Profactor/cv-plot / Benchmark

Class Benchmark

CvPlot/ext/catch2/inc/catch.hpp:7228–7281  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7226namespace Catch {
7227 namespace Benchmark {
7228 struct Benchmark {
7229 Benchmark(std::string &&name)
7230 : name(std::move(name)) {}
7231
7232 template <class FUN>
7233 Benchmark(std::string &&name, FUN &&func)
7234 : fun(std::move(func)), name(std::move(name)) {}
7235
7236 template <typename Clock>
7237 ExecutionPlan<FloatDuration<Clock>> prepare(const IConfig &cfg, Environment<FloatDuration<Clock>> env) const {
7238 auto min_time = env.clock_resolution.mean * Detail::minimum_ticks;
7239 auto run_time = std::max(min_time, std::chrono::duration_cast<decltype(min_time)>(Detail::warmup_time));
7240 auto&& test = Detail::run_for_at_least<Clock>(std::chrono::duration_cast<ClockDuration<Clock>>(run_time), 1, fun);
7241 int new_iters = static_cast<int>(std::ceil(min_time * test.iterations / test.elapsed));
7242 return { new_iters, test.elapsed / test.iterations * new_iters * cfg.benchmarkSamples(), fun, std::chrono::duration_cast<FloatDuration<Clock>>(Detail::warmup_time), Detail::warmup_iterations };
7243 }
7244
7245 template <typename Clock = default_clock>
7246 void run() {
7247 IConfigPtr cfg = getCurrentContext().getConfig();
7248
7249 auto env = Detail::measure_environment<Clock>();
7250
7251 getResultCapture().benchmarkPreparing(name);
7252 CATCH_TRY{
7253 auto plan = user_code([&] {
7254 return prepare<Clock>(*cfg, env);
7255 });
7256
7257 BenchmarkInfo info {
7258 name,
7259 plan.estimated_duration.count(),
7260 plan.iterations_per_sample,
7261 cfg->benchmarkSamples(),
7262 cfg->benchmarkResamples(),
7263 env.clock_resolution.mean.count(),
7264 env.clock_cost.mean.count()
7265 };
7266
7267 getResultCapture().benchmarkStarting(info);
7268
7269 auto samples = user_code([&] {
7270 return plan.template run<Clock>(*cfg, env);
7271 });
7272
7273 auto analysis = Detail::analyse(*cfg, env, samples.begin(), samples.end());
7274 BenchmarkStats<FloatDuration<Clock>> stats{ info, analysis.samples, analysis.mean, analysis.standard_deviation, analysis.outliers, analysis.outlier_variance };
7275 getResultCapture().benchmarkEnded(stats);
7276
7277 } CATCH_CATCH_ALL{
7278 if (translateActiveException() != Detail::benchmarkErrorMsg) // benchmark errors have been reported, otherwise rethrow.
7279 std::rethrow_exception(std::current_exception());
7280 }
7281 }
7282
7283 // sets lambda to be used in fun *and* executes benchmark!
7284 template <typename Fun,

Callers

nothing calls this directly

Calls 1

translateActiveExceptionFunction · 0.85

Tested by

no test coverage detected