| 22 | // estimate of the true cost -- a single sample is too noisy to compare |
| 23 | // scenarios that differ by only a few percent. |
| 24 | template <typename Fn> double time_ms(Fn &&fn, int repeats = 5) { |
| 25 | double best = -1.0; |
| 26 | for (int i = 0; i < repeats; ++i) { |
| 27 | auto start = std::chrono::steady_clock::now(); |
| 28 | fn(); |
| 29 | double ms = std::chrono::duration<double, std::milli>(std::chrono::steady_clock::now() - start).count(); |
| 30 | if (best < 0.0 || ms < best) |
| 31 | best = ms; |
| 32 | } |
| 33 | return best; |
| 34 | } |
| 35 | |
| 36 | std::string ms_str(double ms) { |
| 37 | std::ostringstream out; |
no outgoing calls
no test coverage detected