Skip to content

Commit

Permalink
WIP: Detemplatize EnvrionmentEstimate
Browse files Browse the repository at this point in the history
  • Loading branch information
horenmar committed Aug 31, 2023
1 parent 70b2576 commit fe3df19
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
12 changes: 3 additions & 9 deletions src/catch2/benchmark/catch_environment.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,14 @@

namespace Catch {
namespace Benchmark {
template <typename Duration>
struct EnvironmentEstimate {
Duration mean;
FDuration mean;
OutlierClassification outliers;

template <typename Duration2>
operator EnvironmentEstimate<Duration2>() const {
return { mean, outliers };
}
};
template <typename Clock>
struct Environment {
EnvironmentEstimate<FloatDuration<Clock>> clock_resolution;
EnvironmentEstimate<FloatDuration<Clock>> clock_cost;
EnvironmentEstimate clock_resolution;
EnvironmentEstimate clock_cost;
};
} // namespace Benchmark
} // namespace Catch
Expand Down
8 changes: 4 additions & 4 deletions src/catch2/benchmark/detail/catch_estimate_clock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,16 @@ namespace Catch {
.iterations;
}
template <typename Clock>
EnvironmentEstimate<FloatDuration<Clock>> estimate_clock_resolution(int iterations) {
EnvironmentEstimate 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>)
.result;
return {
FloatDuration<Clock>(mean(r.data(), r.data() + r.size())),
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(FloatDuration<Clock> resolution) {
auto time_limit = (std::min)(
resolution * clock_cost_estimation_tick_limit,
FloatDuration<Clock>(clock_cost_estimation_time_limit));
Expand All @@ -92,7 +92,7 @@ namespace Catch {
.count() ) );
}
return {
FloatDuration<Clock>(mean(times.data(), times.data() + times.size())),
FDuration(mean(times.data(), times.data() + times.size())),
classify_outliers(times.data(), times.data() + times.size()),
};
}
Expand Down

0 comments on commit fe3df19

Please sign in to comment.