// 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 // Adapted from donated nonius code. #ifndef CATCH_ANALYSE_HPP_INCLUDED #define CATCH_ANALYSE_HPP_INCLUDED #include #include #include #include #include #include namespace Catch { namespace Benchmark { namespace Detail { template SampleAnalysis analyse(const IConfig &cfg, Environment, Iterator first, Iterator last) { if (!cfg.benchmarkNoAnalysis()) { std::vector samples; samples.reserve(static_cast(last - first)); for (auto current = first; current != last; ++current) { samples.push_back( current->count() ); } auto analysis = Catch::Benchmark::Detail::analyse_samples(cfg.benchmarkConfidenceInterval(), cfg.benchmarkResamples(), samples.begin(), samples.end()); auto outliers = Catch::Benchmark::Detail::classify_outliers(samples.begin(), samples.end()); auto wrap_estimate = [](Estimate e) { return Estimate { Duration(e.point), Duration(e.lower_bound), Duration(e.upper_bound), e.confidence_interval, }; }; std::vector samples2; samples2.reserve(samples.size()); for (auto s : samples) { samples2.push_back( Duration( s ) ); } return { CATCH_MOVE(samples2), wrap_estimate(analysis.mean), wrap_estimate(analysis.standard_deviation), outliers, analysis.outlier_variance, }; } else { std::vector samples; samples.reserve(static_cast(last - first)); Duration mean = Duration(0); int i = 0; for (auto it = first; it < last; ++it, ++i) { samples.push_back(Duration(*it)); mean += Duration(*it); } mean /= i; return { CATCH_MOVE(samples), Estimate{mean, mean, mean, 0.0}, Estimate{Duration(0), Duration(0), Duration(0), 0.0}, OutlierClassification{}, 0.0 }; } } } // namespace Detail } // namespace Benchmark } // namespace Catch #endif // CATCH_ANALYSE_HPP_INCLUDED