MCPcopy Create free account
hub / github.com/apache/trafficserver / estimate_clock_cost

Function estimate_clock_cost

lib/catch2/catch.hpp:7140–7165  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7138 }
7139 template <typename Clock>
7140 EnvironmentEstimate<FloatDuration<Clock>> estimate_clock_cost(FloatDuration<Clock> resolution) {
7141 auto time_limit = (std::min)(
7142 resolution * clock_cost_estimation_tick_limit,
7143 FloatDuration<Clock>(clock_cost_estimation_time_limit));
7144 auto time_clock = [](int k) {
7145 return Detail::measure<Clock>([k] {
7146 for (int i = 0; i < k; ++i) {
7147 volatile auto ignored = Clock::now();
7148 (void)ignored;
7149 }
7150 }).elapsed;
7151 };
7152 time_clock(1);
7153 int iters = clock_cost_estimation_iterations;
7154 auto&& r = run_for_at_least<Clock>(std::chrono::duration_cast<ClockDuration<Clock>>(clock_cost_estimation_time), iters, time_clock);
7155 std::vector<double> times;
7156 int nsamples = static_cast<int>(std::ceil(time_limit / r.elapsed));
7157 times.reserve(nsamples);
7158 std::generate_n(std::back_inserter(times), nsamples, [time_clock, &r] {
7159 return static_cast<double>((time_clock(r.iterations) / r.iterations).count());
7160 });
7161 return {
7162 FloatDuration<Clock>(mean(times.begin(), times.end())),
7163 classify_outliers(times.begin(), times.end()),
7164 };
7165 }
7166
7167 template <typename Clock>
7168 Environment<FloatDuration<Clock>> measure_environment() {

Callers

nothing calls this directly

Calls 7

meanFunction · 0.85
classify_outliersFunction · 0.85
nowClass · 0.70
reserveMethod · 0.45
countMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected