diff options
| author | Martin Hořeňovský | 2023-08-31 22:04:54 +0200 |
|---|---|---|
| committer | Martin Hořeňovský | 2023-09-08 10:04:19 +0200 |
| commit | 9bba07cb8736d1a949a50afc0b37a6611040db78 (patch) | |
| tree | b0643f67358798666caa3ed33d6ad5fd0d374d80 /src/catch2/benchmark | |
| parent | b4ffba50877bede0d8b19baa92a6882836647c45 (diff) | |
| download | catch3-9bba07cb8736d1a949a50afc0b37a6611040db78.tar.gz | |
Replace vector iterator args in benchmarks with ptr args
Diffstat (limited to 'src/catch2/benchmark')
| -rw-r--r-- | src/catch2/benchmark/detail/catch_analyse.hpp | 9 | ||||
| -rw-r--r-- | src/catch2/benchmark/detail/catch_estimate_clock.hpp | 8 | ||||
| -rw-r--r-- | src/catch2/benchmark/detail/catch_stats.cpp | 34 | ||||
| -rw-r--r-- | src/catch2/benchmark/detail/catch_stats.hpp | 25 |
4 files changed, 40 insertions, 36 deletions
diff --git a/src/catch2/benchmark/detail/catch_analyse.hpp b/src/catch2/benchmark/detail/catch_analyse.hpp index c932ff26..60db7d87 100644 --- a/src/catch2/benchmark/detail/catch_analyse.hpp +++ b/src/catch2/benchmark/detail/catch_analyse.hpp @@ -30,8 +30,13 @@ namespace Catch { 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 analysis = Catch::Benchmark::Detail::analyse_samples( + cfg.benchmarkConfidenceInterval(), + cfg.benchmarkResamples(), + samples.data(), + samples.data() + samples.size() ); + auto outliers = Catch::Benchmark::Detail::classify_outliers( + samples.data(), samples.data() + samples.size() ); auto wrap_estimate = [](Estimate<double> e) { return Estimate<Duration> { diff --git a/src/catch2/benchmark/detail/catch_estimate_clock.hpp b/src/catch2/benchmark/detail/catch_estimate_clock.hpp index 1e916ae4..a0dc2d3d 100644 --- a/src/catch2/benchmark/detail/catch_estimate_clock.hpp +++ b/src/catch2/benchmark/detail/catch_estimate_clock.hpp @@ -63,8 +63,8 @@ namespace Catch { auto r = run_for_at_least<Clock>(std::chrono::duration_cast<ClockDuration<Clock>>(clock_resolution_estimation_time), iterations, &resolution<Clock>) .result; return { - FloatDuration<Clock>(mean(r.begin(), r.end())), - classify_outliers(r.begin(), r.end()), + FloatDuration<Clock>(mean(r.data(), r.data() + r.size())), + classify_outliers(r.data(), r.data() + r.size()), }; } template <typename Clock> @@ -92,8 +92,8 @@ namespace Catch { .count() ) ); } return { - FloatDuration<Clock>(mean(times.begin(), times.end())), - classify_outliers(times.begin(), times.end()), + FloatDuration<Clock>(mean(times.data(), times.data() + times.size())), + classify_outliers(times.data(), times.data() + times.size()), }; } diff --git a/src/catch2/benchmark/detail/catch_stats.cpp b/src/catch2/benchmark/detail/catch_stats.cpp index ea483a30..caad0167 100644 --- a/src/catch2/benchmark/detail/catch_stats.cpp +++ b/src/catch2/benchmark/detail/catch_stats.cpp @@ -30,8 +30,8 @@ namespace Catch { static sample resample( URng& rng, unsigned int resamples, - std::vector<double>::const_iterator first, - std::vector<double>::const_iterator last, + double const* first, + double const* last, Estimator& estimator ) { auto n = static_cast<size_t>( last - first ); std::uniform_int_distribution<decltype( n )> dist( 0, @@ -51,7 +51,7 @@ namespace Catch { dist( rng ) )] ); } const auto estimate = - estimator( resampled.begin(), resampled.end() ); + estimator( resampled.data(), resampled.data() + resampled.size() ); out.push_back( estimate ); } std::sort( out.begin(), out.end() ); @@ -168,8 +168,7 @@ namespace Catch { } static double - standard_deviation( std::vector<double>::const_iterator first, - std::vector<double>::const_iterator last ) { + standard_deviation( double const* first, double const* last ) { auto m = Catch::Benchmark::Detail::mean( first, last ); double variance = std::accumulate( first, @@ -201,7 +200,10 @@ namespace Catch { # pragma GCC diagnostic pop #endif - double weighted_average_quantile(int k, int q, std::vector<double>::iterator first, std::vector<double>::iterator last) { + double weighted_average_quantile( int k, + int q, + double* first, + double* last ) { auto count = last - first; double idx = (count - 1) * k / static_cast<double>(q); int j = static_cast<int>(idx); @@ -217,12 +219,11 @@ namespace Catch { } OutlierClassification - classify_outliers( std::vector<double>::const_iterator first, - std::vector<double>::const_iterator last ) { + classify_outliers( double const* first, double const* last ) { std::vector<double> copy( first, last ); - auto q1 = weighted_average_quantile( 1, 4, copy.begin(), copy.end() ); - auto q3 = weighted_average_quantile( 3, 4, copy.begin(), copy.end() ); + auto q1 = weighted_average_quantile( 1, 4, copy.data(), copy.data() + copy.size() ); + auto q3 = weighted_average_quantile( 3, 4, copy.data(), copy.data() + copy.size() ); auto iqr = q3 - q1; auto los = q1 - ( iqr * 3. ); auto lom = q1 - ( iqr * 1.5 ); @@ -246,8 +247,7 @@ namespace Catch { return o; } - double mean( std::vector<double>::const_iterator first, - std::vector<double>::const_iterator last ) { + double mean( double const* first, double const* last ) { auto count = last - first; double sum = 0.; while (first != last) { @@ -280,8 +280,8 @@ namespace Catch { bootstrap_analysis analyse_samples(double confidence_level, unsigned int n_resamples, - std::vector<double>::iterator first, - std::vector<double>::iterator last) { + double* first, + double* last) { CATCH_INTERNAL_START_WARNINGS_SUPPRESSION CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS static std::random_device entropy; @@ -293,8 +293,7 @@ namespace Catch { auto stddev = &standard_deviation; #if defined(CATCH_CONFIG_USE_ASYNC) - auto Estimate = [=](double(*f)(std::vector<double>::const_iterator, - std::vector<double>::const_iterator)) { + auto Estimate = [=](double(*f)(double const*, double const*)) { auto seed = entropy(); return std::async(std::launch::async, [=] { std::mt19937 rng(seed); @@ -309,8 +308,7 @@ namespace Catch { auto mean_estimate = mean_future.get(); auto stddev_estimate = stddev_future.get(); #else - auto Estimate = [=](double(*f)(std::vector<double>::const_iterator, - std::vector<double>::const_iterator)) { + auto Estimate = [=](double(*f)(double const* , double const*)) { auto seed = entropy(); std::mt19937 rng(seed); auto resampled = resample(rng, n_resamples, first, last, f); diff --git a/src/catch2/benchmark/detail/catch_stats.hpp b/src/catch2/benchmark/detail/catch_stats.hpp index c1ce5664..54621670 100644 --- a/src/catch2/benchmark/detail/catch_stats.hpp +++ b/src/catch2/benchmark/detail/catch_stats.hpp @@ -26,19 +26,20 @@ namespace Catch { // to centralize warning suppression bool directCompare( double lhs, double rhs ); - double weighted_average_quantile(int k, int q, std::vector<double>::iterator first, std::vector<double>::iterator last); + double weighted_average_quantile( int k, + int q, + double* first, + double* last ); OutlierClassification - classify_outliers( std::vector<double>::const_iterator first, - std::vector<double>::const_iterator last ); + classify_outliers( double const* first, double const* last ); - double mean( std::vector<double>::const_iterator first, - std::vector<double>::const_iterator last ); + double mean( double const* first, double const* last ); template <typename Estimator> sample jackknife(Estimator&& estimator, - std::vector<double>::iterator first, - std::vector<double>::iterator last) { + double* first, + double* last) { auto n = static_cast<size_t>(last - first); auto second = first; ++second; @@ -63,8 +64,8 @@ namespace Catch { template <typename Estimator> Estimate<double> bootstrap( double confidence_level, - std::vector<double>::iterator first, - std::vector<double>::iterator last, + double* first, + double* last, sample const& resample, Estimator&& estimator ) { auto n_samples = last - first; @@ -74,7 +75,7 @@ namespace Catch { if (n_samples == 1) return { point, point, point, confidence_level }; sample jack = jackknife(estimator, first, last); - double jack_mean = mean(jack.begin(), jack.end()); + double jack_mean = mean(jack.data(), jack.data() + jack.size()); double sum_squares = 0, sum_cubes = 0; for (double x : jack) { auto difference = jack_mean - x; @@ -116,8 +117,8 @@ namespace Catch { bootstrap_analysis analyse_samples(double confidence_level, unsigned int n_resamples, - std::vector<double>::iterator first, - std::vector<double>::iterator last); + double* first, + double* last); } // namespace Detail } // namespace Benchmark } // namespace Catch |