diff options
| author | Martin Hořeňovský | 2023-03-31 10:44:29 +0200 |
|---|---|---|
| committer | Martin Hořeňovský | 2023-03-31 19:31:51 +0200 |
| commit | 9f08097f55eb29a61efcdb4af41952a67e155215 (patch) | |
| tree | 04a4e437ee8384da04758380abe3d925ecbf79b1 /src/catch2/benchmark | |
| parent | 1f881ab4641b866304b818a063164dae976dba5f (diff) | |
| download | catch3-9f08097f55eb29a61efcdb4af41952a67e155215.tar.gz | |
Cleanup internal includes by splitting out some event structs
* Split out BenchmarkInfo and BenchmarkStats to their own header
* Outline BenchmarkStats<> declaration to separate header
* Split out TestRunInfo into its own header
These changes let us remove the large `interfaces_reporter.hpp`
include from `benchmark.hpp`, and replace it with
`interfaces_capture.hpp` in `run_context.hpp`.
I also cleaned out `interfaces_repoter.hpp` from reporter headers
that depend on `reporter_common_base.hpp`. This will not change
anything in the actual inclusion set, but makes it logically
more consistent.
Diffstat (limited to 'src/catch2/benchmark')
| -rw-r--r-- | src/catch2/benchmark/catch_benchmark.hpp | 2 | ||||
| -rw-r--r-- | src/catch2/benchmark/catch_benchmark_all.hpp | 2 | ||||
| -rw-r--r-- | src/catch2/benchmark/detail/catch_benchmark_stats.hpp | 64 | ||||
| -rw-r--r-- | src/catch2/benchmark/detail/catch_benchmark_stats_fwd.hpp | 23 |
4 files changed, 90 insertions, 1 deletions
diff --git a/src/catch2/benchmark/catch_benchmark.hpp b/src/catch2/benchmark/catch_benchmark.hpp index 57adc67a..3623133d 100644 --- a/src/catch2/benchmark/catch_benchmark.hpp +++ b/src/catch2/benchmark/catch_benchmark.hpp @@ -19,7 +19,7 @@ #include <catch2/interfaces/catch_interfaces_capture.hpp> #include <catch2/interfaces/catch_interfaces_config.hpp> #include <catch2/interfaces/catch_interfaces_registry_hub.hpp> -#include <catch2/interfaces/catch_interfaces_reporter.hpp> +#include <catch2/benchmark/detail/catch_benchmark_stats.hpp> #include <catch2/benchmark/catch_clock.hpp> #include <catch2/benchmark/catch_environment.hpp> #include <catch2/benchmark/catch_execution_plan.hpp> diff --git a/src/catch2/benchmark/catch_benchmark_all.hpp b/src/catch2/benchmark/catch_benchmark_all.hpp index eb81f238..56fc7c74 100644 --- a/src/catch2/benchmark/catch_benchmark_all.hpp +++ b/src/catch2/benchmark/catch_benchmark_all.hpp @@ -33,6 +33,8 @@ #include <catch2/benchmark/catch_sample_analysis.hpp> #include <catch2/benchmark/detail/catch_analyse.hpp> #include <catch2/benchmark/detail/catch_benchmark_function.hpp> +#include <catch2/benchmark/detail/catch_benchmark_stats.hpp> +#include <catch2/benchmark/detail/catch_benchmark_stats_fwd.hpp> #include <catch2/benchmark/detail/catch_complete_invoke.hpp> #include <catch2/benchmark/detail/catch_estimate_clock.hpp> #include <catch2/benchmark/detail/catch_measure.hpp> diff --git a/src/catch2/benchmark/detail/catch_benchmark_stats.hpp b/src/catch2/benchmark/detail/catch_benchmark_stats.hpp new file mode 100644 index 00000000..a8b3494e --- /dev/null +++ b/src/catch2/benchmark/detail/catch_benchmark_stats.hpp @@ -0,0 +1,64 @@ + +// 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 +#ifndef CATCH_BENCHMARK_STATS_HPP_INCLUDED +#define CATCH_BENCHMARK_STATS_HPP_INCLUDED + +#include <catch2/internal/catch_move_and_forward.hpp> +#include <catch2/benchmark/catch_estimate.hpp> +#include <catch2/benchmark/catch_outlier_classification.hpp> +// The fwd decl & default specialization needs to be seen by VS2017 before +// BenchmarkStats itself, or VS2017 will report compilation error. +#include <catch2/benchmark/detail/catch_benchmark_stats_fwd.hpp> + +#include <string> +#include <vector> + +namespace Catch { + + struct BenchmarkInfo { + std::string name; + double estimatedDuration; + int iterations; + unsigned int samples; + unsigned int resamples; + double clockResolution; + double clockCost; + }; + + template <class Duration> + struct BenchmarkStats { + BenchmarkInfo info; + + std::vector<Duration> samples; + Benchmark::Estimate<Duration> mean; + Benchmark::Estimate<Duration> standardDeviation; + Benchmark::OutlierClassification outliers; + double outlierVariance; + + template <typename Duration2> + operator BenchmarkStats<Duration2>() const { + std::vector<Duration2> samples2; + samples2.reserve(samples.size()); + for (auto const& sample : samples) { + samples2.push_back(Duration2(sample)); + } + return { + info, + CATCH_MOVE(samples2), + mean, + standardDeviation, + outliers, + outlierVariance, + }; + } + }; + + +} // end namespace Catch + +#endif // CATCH_BENCHMARK_STATS_HPP_INCLUDED diff --git a/src/catch2/benchmark/detail/catch_benchmark_stats_fwd.hpp b/src/catch2/benchmark/detail/catch_benchmark_stats_fwd.hpp new file mode 100644 index 00000000..60772561 --- /dev/null +++ b/src/catch2/benchmark/detail/catch_benchmark_stats_fwd.hpp @@ -0,0 +1,23 @@ + +// 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 +#ifndef CATCH_BENCHMARK_STATS_FWD_HPP_INCLUDED +#define CATCH_BENCHMARK_STATS_FWD_HPP_INCLUDED + +#include <chrono> + +namespace Catch { + + // We cannot forward declare the type with default template argument + // multiple times, so it is split out into a separate header so that + // we can prevent multiple declarations in dependees + template <typename Duration = std::chrono::duration<double, std::nano>> + struct BenchmarkStats; + +} // end namespace Catch + +#endif // CATCH_BENCHMARK_STATS_FWD_HPP_INCLUDED |