diff options
| author | khyperia | 2020-01-27 15:43:27 +0100 |
|---|---|---|
| committer | Martin Hořeňovský | 2020-02-16 15:44:23 +0100 |
| commit | 3c7e737a7bcf2d2059b1db2a5a221f76806ae8b0 (patch) | |
| tree | bcbf40fe8e4914c8ecc3a585066933bf871652c7 /src | |
| parent | e880da93bd335e59a0d4b00bfcb9f06ab4b7c847 (diff) | |
| download | catch3-3c7e737a7bcf2d2059b1db2a5a221f76806ae8b0.tar.gz | |
Allow configuring of benchmark warmup time
Diffstat (limited to 'src')
| -rw-r--r-- | src/catch2/benchmark/catch_benchmark.hpp | 4 | ||||
| -rw-r--r-- | src/catch2/catch_commandline.cpp | 3 | ||||
| -rw-r--r-- | src/catch2/catch_config.cpp | 9 | ||||
| -rw-r--r-- | src/catch2/catch_config.hpp | 2 | ||||
| -rw-r--r-- | src/catch2/catch_interfaces_config.h | 2 |
5 files changed, 14 insertions, 6 deletions
diff --git a/src/catch2/benchmark/catch_benchmark.hpp b/src/catch2/benchmark/catch_benchmark.hpp index a6ffcf7c..154105c5 100644 --- a/src/catch2/benchmark/catch_benchmark.hpp +++ b/src/catch2/benchmark/catch_benchmark.hpp @@ -44,10 +44,10 @@ namespace Catch { template <typename Clock> ExecutionPlan<FloatDuration<Clock>> prepare(const IConfig &cfg, Environment<FloatDuration<Clock>> env) const { auto min_time = env.clock_resolution.mean * Detail::minimum_ticks; - auto run_time = std::max(min_time, std::chrono::duration_cast<decltype(min_time)>(Detail::warmup_time)); + auto run_time = std::max(min_time, std::chrono::duration_cast<decltype(min_time)>(cfg.benchmarkWarmupTime())); auto&& test = Detail::run_for_at_least<Clock>(std::chrono::duration_cast<ClockDuration<Clock>>(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(), fun, std::chrono::duration_cast<FloatDuration<Clock>>(Detail::warmup_time), Detail::warmup_iterations }; + return { new_iters, test.elapsed / test.iterations * new_iters * cfg.benchmarkSamples(), fun, std::chrono::duration_cast<FloatDuration<Clock>>(cfg.benchmarkWarmupTime()), Detail::warmup_iterations }; } template <typename Clock = default_clock> diff --git a/src/catch2/catch_commandline.cpp b/src/catch2/catch_commandline.cpp index 3640a226..3c453f48 100644 --- a/src/catch2/catch_commandline.cpp +++ b/src/catch2/catch_commandline.cpp @@ -210,6 +210,9 @@ namespace Catch { | Opt( config.benchmarkNoAnalysis ) ["--benchmark-no-analysis"] ( "perform only measurements; do not perform any analysis" ) + | Opt( config.benchmarkWarmupTime, "benchmarkWarmupTime" ) + ["--benchmark-warmup-time"] + ( "amount of time in milliseconds spent on warming up each test (default: 100)" ) | Arg( config.testsOrTags, "test name|pattern|tags" ) ( "which test or tests to use" ); diff --git a/src/catch2/catch_config.cpp b/src/catch2/catch_config.cpp index ea7ec3de..7c0393da 100644 --- a/src/catch2/catch_config.cpp +++ b/src/catch2/catch_config.cpp @@ -75,10 +75,11 @@ namespace Catch { bool Config::showInvisibles() const { return m_data.showInvisibles; } Verbosity Config::verbosity() const { return m_data.verbosity; } - bool Config::benchmarkNoAnalysis() const { return m_data.benchmarkNoAnalysis; } - int Config::benchmarkSamples() const { return m_data.benchmarkSamples; } - double Config::benchmarkConfidenceInterval() const { return m_data.benchmarkConfidenceInterval; } - unsigned int Config::benchmarkResamples() const { return m_data.benchmarkResamples; } + bool Config::benchmarkNoAnalysis() const { return m_data.benchmarkNoAnalysis; } + int Config::benchmarkSamples() const { return m_data.benchmarkSamples; } + double Config::benchmarkConfidenceInterval() const { return m_data.benchmarkConfidenceInterval; } + unsigned int Config::benchmarkResamples() const { return m_data.benchmarkResamples; } + std::chrono::milliseconds Config::benchmarkWarmupTime() const { return std::chrono::milliseconds(m_data.benchmarkWarmupTime); } IStream const* Config::openStream() { return Catch::makeStream(m_data.outputFilename); diff --git a/src/catch2/catch_config.hpp b/src/catch2/catch_config.hpp index 55fa5ed8..14972121 100644 --- a/src/catch2/catch_config.hpp +++ b/src/catch2/catch_config.hpp @@ -43,6 +43,7 @@ namespace Catch { unsigned int benchmarkSamples = 100; double benchmarkConfidenceInterval = 0.95; unsigned int benchmarkResamples = 100000; + std::chrono::milliseconds::rep benchmarkWarmupTime = 100; Verbosity verbosity = Verbosity::Normal; WarnAbout::What warnings = WarnAbout::Nothing; @@ -108,6 +109,7 @@ namespace Catch { int benchmarkSamples() const override; double benchmarkConfidenceInterval() const override; unsigned int benchmarkResamples() const override; + std::chrono::milliseconds benchmarkWarmupTime() const override; private: diff --git a/src/catch2/catch_interfaces_config.h b/src/catch2/catch_interfaces_config.h index 1ef601fe..ddaf2e8e 100644 --- a/src/catch2/catch_interfaces_config.h +++ b/src/catch2/catch_interfaces_config.h @@ -11,6 +11,7 @@ #include <catch2/catch_common.h> #include <catch2/catch_option.hpp> +#include <chrono> #include <iosfwd> #include <string> #include <vector> @@ -81,6 +82,7 @@ namespace Catch { virtual int benchmarkSamples() const = 0; virtual double benchmarkConfidenceInterval() const = 0; virtual unsigned int benchmarkResamples() const = 0; + virtual std::chrono::milliseconds benchmarkWarmupTime() const = 0; }; using IConfigPtr = std::shared_ptr<IConfig const>; |