// Copyright Catch2 Authors // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE.txt or copy at // https://www.boost.org/LICENSE_1_0.txt) // SPDX-License-Identifier: BSL-1.0 // Adapted from donated nonius code. #ifndef CATCH_EXECUTION_PLAN_HPP_INCLUDED #define CATCH_EXECUTION_PLAN_HPP_INCLUDED #include #include #include #include #include #include #include #include namespace Catch { namespace Benchmark { template struct ExecutionPlan { int iterations_per_sample; Duration estimated_duration; Detail::BenchmarkFunction benchmark; Duration warmup_time; int warmup_iterations; template operator ExecutionPlan() const { return { iterations_per_sample, estimated_duration, benchmark, warmup_time, warmup_iterations }; } template std::vector> run(const IConfig &cfg, Environment> env) const { // warmup a bit Detail::run_for_at_least(std::chrono::duration_cast>(warmup_time), warmup_iterations, Detail::repeat(now{})); std::vector> times; times.reserve(cfg.benchmarkSamples()); std::generate_n(std::back_inserter(times), cfg.benchmarkSamples(), [this, env] { Detail::ChronometerModel model; this->benchmark(Chronometer(model, iterations_per_sample)); auto sample_time = model.elapsed() - env.clock_cost.mean; if (sample_time < FloatDuration::zero()) sample_time = FloatDuration::zero(); return sample_time / iterations_per_sample; }); return times; } }; } // namespace Benchmark } // namespace Catch #endif // CATCH_EXECUTION_PLAN_HPP_INCLUDED