Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/src/Progmasoft/Catch3/Benchmark/Benchmark.cpp
diff options
context:
space:
mode:
authorLeitwolf2026-10-25 10:31:36 +0300
committerGitHub2026-10-25 10:31:36 +0300
commitd2e3e074bb2e1b8ffd9fc990d0b87667ea602f58 (patch)
tree0bce4462b2e190c39b3e1c5f697e3e4abd1a5e2a /src/Progmasoft/Catch3/Benchmark/Benchmark.cpp
parent13f81a480a93807c14dddb5abdb97355ced4d4c5 (diff)
parent126dc333564cb72b5115d9a9242d66694694b6d0 (diff)
downloadcatch3-d2e3e074bb2e1b8ffd9fc990d0b87667ea602f58.tar.gz
Merge pull request #18 from Progmasoft/build/catch3-identity
Give Catch3 its own build names and headers
Diffstat (limited to 'src/Progmasoft/Catch3/Benchmark/Benchmark.cpp')
-rw-r--r--src/Progmasoft/Catch3/Benchmark/Benchmark.cpp54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/Progmasoft/Catch3/Benchmark/Benchmark.cpp b/src/Progmasoft/Catch3/Benchmark/Benchmark.cpp
new file mode 100644
index 00000000..8967b12c
--- /dev/null
+++ b/src/Progmasoft/Catch3/Benchmark/Benchmark.cpp
@@ -0,0 +1,54 @@
+
+// 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
+
+#include <Progmasoft/Catch3/Benchmark/Benchmark.hpp>
+
+#include <algorithm>
+#include <chrono>
+#include <cmath>
+
+namespace Catch {
+ namespace Benchmark {
+ namespace Detail {
+
+ Environment measure_environment_default() {
+ return Detail::measure_environment<default_clock>();
+ }
+
+ ExecutionPlan prepare_default( const IConfig& cfg,
+ Environment env,
+ BenchmarkFunction&& fun ) {
+ // This mirrors Benchmark::prepare<default_clock>(), but with the
+ // clock fixed so it is instantiated once here in the library.
+ auto min_time = env.clock_resolution.mean * Detail::minimum_ticks;
+ auto run_time = std::max(
+ min_time,
+ std::chrono::duration_cast<decltype( min_time )>(
+ cfg.benchmarkWarmupTime() ) );
+ auto&& test = Detail::run_for_at_least<default_clock>(
+ std::chrono::duration_cast<IDuration>( run_time ), 1, fun );
+ int new_iters = static_cast<int>(
+ std::ceil( min_time * test.iterations / test.elapsed ) );
+ return { new_iters,
+ test.elapsed / test.iterations * new_iters *
+ cfg.benchmarkSamples(),
+ CATCH_MOVE( fun ),
+ std::chrono::duration_cast<FDuration>(
+ cfg.benchmarkWarmupTime() ),
+ Detail::warmup_iterations };
+ }
+
+ std::vector<FDuration> run_plan_default( ExecutionPlan const& plan,
+ const IConfig& cfg,
+ Environment env ) {
+ return plan.run<default_clock>( cfg, env );
+ }
+
+ } // namespace Detail
+ } // namespace Benchmark
+} // namespace Catch