File indexing completed on 2025-01-30 10:02:47
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef CATCH_ANALYSE_HPP_INCLUDED
0011 #define CATCH_ANALYSE_HPP_INCLUDED
0012
0013 #include <catch2/benchmark/catch_environment.hpp>
0014 #include <catch2/benchmark/catch_sample_analysis.hpp>
0015 #include <catch2/benchmark/detail/catch_stats.hpp>
0016 #include <catch2/interfaces/catch_interfaces_config.hpp>
0017 #include <catch2/internal/catch_move_and_forward.hpp>
0018
0019 #include <vector>
0020
0021 namespace Catch {
0022 namespace Benchmark {
0023 namespace Detail {
0024 template <typename Duration, typename Iterator>
0025 SampleAnalysis<Duration> analyse(const IConfig &cfg, Environment<Duration>, Iterator first, Iterator last) {
0026 if (!cfg.benchmarkNoAnalysis()) {
0027 std::vector<double> samples;
0028 samples.reserve(static_cast<size_t>(last - first));
0029 for (auto current = first; current != last; ++current) {
0030 samples.push_back( current->count() );
0031 }
0032
0033 auto analysis = Catch::Benchmark::Detail::analyse_samples(cfg.benchmarkConfidenceInterval(), cfg.benchmarkResamples(), samples.begin(), samples.end());
0034 auto outliers = Catch::Benchmark::Detail::classify_outliers(samples.begin(), samples.end());
0035
0036 auto wrap_estimate = [](Estimate<double> e) {
0037 return Estimate<Duration> {
0038 Duration(e.point),
0039 Duration(e.lower_bound),
0040 Duration(e.upper_bound),
0041 e.confidence_interval,
0042 };
0043 };
0044 std::vector<Duration> samples2;
0045 samples2.reserve(samples.size());
0046 for (auto s : samples) {
0047 samples2.push_back( Duration( s ) );
0048 }
0049
0050 return {
0051 CATCH_MOVE(samples2),
0052 wrap_estimate(analysis.mean),
0053 wrap_estimate(analysis.standard_deviation),
0054 outliers,
0055 analysis.outlier_variance,
0056 };
0057 } else {
0058 std::vector<Duration> samples;
0059 samples.reserve(static_cast<size_t>(last - first));
0060
0061 Duration mean = Duration(0);
0062 int i = 0;
0063 for (auto it = first; it < last; ++it, ++i) {
0064 samples.push_back(Duration(*it));
0065 mean += Duration(*it);
0066 }
0067 mean /= i;
0068
0069 return {
0070 CATCH_MOVE(samples),
0071 Estimate<Duration>{mean, mean, mean, 0.0},
0072 Estimate<Duration>{Duration(0), Duration(0), Duration(0), 0.0},
0073 OutlierClassification{},
0074 0.0
0075 };
0076 }
0077 }
0078 }
0079 }
0080 }
0081
0082 #endif