| 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() { |