From 0c6fda6e7dfbd1a46ad02b692eb90668575df9dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ho=C5=99e=C5=88ovsk=C3=BD?= Date: Tue, 19 May 2020 18:12:25 +0200 Subject: [PATCH] Cleanup benchmark headers a tiny bit --- src/catch2/benchmark/detail/catch_stats.cpp | 21 +++++++++++++++++++++ src/catch2/benchmark/detail/catch_stats.hpp | 19 ------------------- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/src/catch2/benchmark/detail/catch_stats.cpp b/src/catch2/benchmark/detail/catch_stats.cpp index 11ca81b4..c583f70c 100644 --- a/src/catch2/benchmark/detail/catch_stats.cpp +++ b/src/catch2/benchmark/detail/catch_stats.cpp @@ -21,6 +21,27 @@ #endif namespace { + +using Catch::Benchmark::Detail::sample; + + template + sample resample(URng& rng, int resamples, std::vector::iterator first, std::vector::iterator last, Estimator& estimator) { + auto n = last - first; + std::uniform_int_distribution dist(0, n - 1); + + sample out; + out.reserve(resamples); + std::generate_n(std::back_inserter(out), resamples, [n, first, &estimator, &dist, &rng] { + std::vector resampled; + resampled.reserve(n); + std::generate_n(std::back_inserter(resampled), n, [first, &dist, &rng] { return first[dist(rng)]; }); + return estimator(resampled.begin(), resampled.end()); + }); + std::sort(out.begin(), out.end()); + return out; + } + + double erf_inv(double x) { // Code accompanying the article "Approximating the erfinv function" in GPU Computing Gems, Volume 2 double w, p; diff --git a/src/catch2/benchmark/detail/catch_stats.hpp b/src/catch2/benchmark/detail/catch_stats.hpp index a8690c45..d43925ab 100644 --- a/src/catch2/benchmark/detail/catch_stats.hpp +++ b/src/catch2/benchmark/detail/catch_stats.hpp @@ -18,12 +18,10 @@ #include #include #include -#include #include #include #include #include -#include namespace Catch { namespace Benchmark { @@ -63,23 +61,6 @@ namespace Catch { return sum / count; } - template - sample resample(URng& rng, int resamples, Iterator first, Iterator last, Estimator& estimator) { - auto n = last - first; - std::uniform_int_distribution dist(0, n - 1); - - sample out; - out.reserve(resamples); - std::generate_n(std::back_inserter(out), resamples, [n, first, &estimator, &dist, &rng] { - std::vector resampled; - resampled.reserve(n); - std::generate_n(std::back_inserter(resampled), n, [first, &dist, &rng] { return first[dist(rng)]; }); - return estimator(resampled.begin(), resampled.end()); - }); - std::sort(out.begin(), out.end()); - return out; - } - template sample jackknife(Estimator&& estimator, Iterator first, Iterator last) { auto n = last - first;