diff options
| author | Martin Hořeňovský | 2023-08-31 21:52:08 +0200 |
|---|---|---|
| committer | Martin Hořeňovský | 2023-09-08 10:04:31 +0200 |
| commit | 47a2c969380259e899f471edde84f06a6d687dc9 (patch) | |
| tree | 28bfe7778e7a4e278f2ba093a7928301f5e3760d /tests/SelfTest | |
| parent | fb96279aedc7472326189823078299abb2dad9a4 (diff) | |
| download | catch3-47a2c969380259e899f471edde84f06a6d687dc9.tar.gz | |
Reduce the number of templates in Benchmarking
The basic idea was to reduce the number of things dependent on the `Clock`
type. To that end, I replaced `Duration<Clock>` with `IDuration` typedef
for `std::nanoseconds`, and `FloatDuration<Clock>` with `FDuration`
typedef for `Duration<double, std::nano>`. We can generally assume that
any clock's duration can be expressed in nanoseconds, as long as we insert
`duration_cast`s into the right places.
Note that we cannot remove all dependence on `Clock` as a template
arguments, because functions that actually measure the elapsed time have
to use the Clock.
We also changed some template function arguments to pass plain function
pointers, so that the actual implementation can be placed into a cpp file.
Diffstat (limited to 'tests/SelfTest')
| -rw-r--r-- | tests/SelfTest/IntrospectiveTests/InternalBenchmark.tests.cpp | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/tests/SelfTest/IntrospectiveTests/InternalBenchmark.tests.cpp b/tests/SelfTest/IntrospectiveTests/InternalBenchmark.tests.cpp index 34ed8814..bc8d715b 100644 --- a/tests/SelfTest/IntrospectiveTests/InternalBenchmark.tests.cpp +++ b/tests/SelfTest/IntrospectiveTests/InternalBenchmark.tests.cpp @@ -292,15 +292,13 @@ TEST_CASE("analyse", "[approvals][benchmark]") { data.benchmarkSamples = 99; Catch::Config config{data}; - using Duration = Catch::Benchmark::FloatDuration<Catch::Benchmark::default_clock>; - - Catch::Benchmark::Environment<Duration> env; - std::vector<Duration> samples(99); + using FDuration = Catch::Benchmark::FDuration; + std::vector<FDuration> samples(99); for (size_t i = 0; i < samples.size(); ++i) { - samples[i] = Duration(23 + (i % 3 - 1)); + samples[i] = FDuration(23 + (i % 3 - 1)); } - auto analysis = Catch::Benchmark::Detail::analyse(config, env, samples.begin(), samples.end()); + auto analysis = Catch::Benchmark::Detail::analyse(config, samples.data(), samples.data() + samples.size()); CHECK( analysis.mean.point.count() == 23 ); CHECK( analysis.mean.lower_bound.count() < 23 ); CHECK(analysis.mean.lower_bound.count() > 22); @@ -333,15 +331,13 @@ TEST_CASE("analyse no analysis", "[benchmark]") { data.benchmarkSamples = 99; Catch::Config config{ data }; - using Duration = Catch::Benchmark::FloatDuration<Catch::Benchmark::default_clock>; - - Catch::Benchmark::Environment<Duration> env; - std::vector<Duration> samples(99); + using FDuration = Catch::Benchmark::FDuration; + std::vector<FDuration> samples(99); for (size_t i = 0; i < samples.size(); ++i) { - samples[i] = Duration(23 + (i % 3 - 1)); + samples[i] = FDuration(23 + (i % 3 - 1)); } - auto analysis = Catch::Benchmark::Detail::analyse(config, env, samples.begin(), samples.end()); + auto analysis = Catch::Benchmark::Detail::analyse(config, samples.data(), samples.data() + samples.size()); CHECK(analysis.mean.point.count() == 23); CHECK(analysis.mean.lower_bound.count() == 23); CHECK(analysis.mean.upper_bound.count() == 23); |