aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/catch2/benchmark/detail/catch_estimate_clock.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/catch2/benchmark/detail/catch_estimate_clock.hpp')
-rw-r--r--src/catch2/benchmark/detail/catch_estimate_clock.hpp64
1 files changed, 34 insertions, 30 deletions
diff --git a/src/catch2/benchmark/detail/catch_estimate_clock.hpp b/src/catch2/benchmark/detail/catch_estimate_clock.hpp
index 907773f2..918484a9 100644
--- a/src/catch2/benchmark/detail/catch_estimate_clock.hpp
+++ b/src/catch2/benchmark/detail/catch_estimate_clock.hpp
@@ -19,7 +19,6 @@
#include <catch2/internal/catch_unique_ptr.hpp>
#include <algorithm>
-#include <iterator>
#include <vector>
#include <cmath>
@@ -30,46 +29,49 @@ namespace Catch {
std::vector<double> resolution(int k) {
std::vector<TimePoint<Clock>> times;
times.reserve(static_cast<size_t>(k + 1));
- std::generate_n(std::back_inserter(times), k + 1, now<Clock>{});
+ for ( int i = 0; i < k + 1; ++i ) {
+ times.push_back( Clock::now() );
+ }
std::vector<double> deltas;
deltas.reserve(static_cast<size_t>(k));
- std::transform(std::next(times.begin()), times.end(), times.begin(),
- std::back_inserter(deltas),
- [](TimePoint<Clock> a, TimePoint<Clock> b) { return static_cast<double>((a - b).count()); });
+ for ( size_t idx = 1; idx < times.size(); ++idx ) {
+ deltas.push_back( static_cast<double>(
+ ( times[idx] - times[idx - 1] ).count() ) );
+ }
return deltas;
}
- const auto warmup_iterations = 10000;
- const auto warmup_time = std::chrono::milliseconds(100);
- const auto minimum_ticks = 1000;
- const auto warmup_seed = 10000;
- const auto clock_resolution_estimation_time = std::chrono::milliseconds(500);
- const auto clock_cost_estimation_time_limit = std::chrono::seconds(1);
- const auto clock_cost_estimation_tick_limit = 100000;
- const auto clock_cost_estimation_time = std::chrono::milliseconds(10);
- const auto clock_cost_estimation_iterations = 10000;
+ constexpr auto warmup_iterations = 10000;
+ constexpr auto warmup_time = std::chrono::milliseconds(100);
+ constexpr auto minimum_ticks = 1000;
+ constexpr auto warmup_seed = 10000;
+ constexpr auto clock_resolution_estimation_time = std::chrono::milliseconds(500);
+ constexpr auto clock_cost_estimation_time_limit = std::chrono::seconds(1);
+ constexpr auto clock_cost_estimation_tick_limit = 100000;
+ constexpr auto clock_cost_estimation_time = std::chrono::milliseconds(10);
+ constexpr auto clock_cost_estimation_iterations = 10000;
template <typename Clock>
int warmup() {
- return run_for_at_least<Clock>(std::chrono::duration_cast<ClockDuration<Clock>>(warmup_time), warmup_seed, &resolution<Clock>)
+ return run_for_at_least<Clock>(std::chrono::duration_cast<IDuration>(warmup_time), warmup_seed, &resolution<Clock>)
.iterations;
}
template <typename Clock>
- EnvironmentEstimate<FloatDuration<Clock>> estimate_clock_resolution(int iterations) {
- auto r = run_for_at_least<Clock>(std::chrono::duration_cast<ClockDuration<Clock>>(clock_resolution_estimation_time), iterations, &resolution<Clock>)
+ EnvironmentEstimate estimate_clock_resolution(int iterations) {
+ auto r = run_for_at_least<Clock>(std::chrono::duration_cast<IDuration>(clock_resolution_estimation_time), iterations, &resolution<Clock>)
.result;
return {
- FloatDuration<Clock>(mean(r.begin(), r.end())),
- classify_outliers(r.begin(), r.end()),
+ FDuration(mean(r.data(), r.data() + r.size())),
+ classify_outliers(r.data(), r.data() + r.size()),
};
}
template <typename Clock>
- EnvironmentEstimate<FloatDuration<Clock>> estimate_clock_cost(FloatDuration<Clock> resolution) {
+ EnvironmentEstimate estimate_clock_cost(FDuration resolution) {
auto time_limit = (std::min)(
resolution * clock_cost_estimation_tick_limit,
- FloatDuration<Clock>(clock_cost_estimation_time_limit));
+ FDuration(clock_cost_estimation_time_limit));
auto time_clock = [](int k) {
return Detail::measure<Clock>([k] {
for (int i = 0; i < k; ++i) {
@@ -80,26 +82,28 @@ namespace Catch {
};
time_clock(1);
int iters = clock_cost_estimation_iterations;
- auto&& r = run_for_at_least<Clock>(std::chrono::duration_cast<ClockDuration<Clock>>(clock_cost_estimation_time), iters, time_clock);
+ auto&& r = run_for_at_least<Clock>(std::chrono::duration_cast<IDuration>(clock_cost_estimation_time), iters, time_clock);
std::vector<double> times;
int nsamples = static_cast<int>(std::ceil(time_limit / r.elapsed));
times.reserve(static_cast<size_t>(nsamples));
- std::generate_n(std::back_inserter(times), nsamples, [time_clock, &r] {
- return static_cast<double>((time_clock(r.iterations) / r.iterations).count());
- });
+ for ( int s = 0; s < nsamples; ++s ) {
+ times.push_back( static_cast<double>(
+ ( time_clock( r.iterations ) / r.iterations )
+ .count() ) );
+ }
return {
- FloatDuration<Clock>(mean(times.begin(), times.end())),
- classify_outliers(times.begin(), times.end()),
+ FDuration(mean(times.data(), times.data() + times.size())),
+ classify_outliers(times.data(), times.data() + times.size()),
};
}
template <typename Clock>
- Environment<FloatDuration<Clock>> measure_environment() {
+ Environment measure_environment() {
#if defined(__clang__)
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wexit-time-destructors"
#endif
- static Catch::Detail::unique_ptr<Environment<FloatDuration<Clock>>> env;
+ static Catch::Detail::unique_ptr<Environment> env;
#if defined(__clang__)
# pragma clang diagnostic pop
#endif
@@ -111,7 +115,7 @@ namespace Catch {
auto resolution = Detail::estimate_clock_resolution<Clock>(iters);
auto cost = Detail::estimate_clock_cost<Clock>(resolution.mean);
- env = Catch::Detail::make_unique<Environment<FloatDuration<Clock>>>( Environment<FloatDuration<Clock>>{resolution, cost} );
+ env = Catch::Detail::make_unique<Environment>( Environment{resolution, cost} );
return *env;
}
} // namespace Detail