1 #ifndef __UTILITY_TIMING_H__
2 #define __UTILITY_TIMING_H__
27 using Clock = std::chrono::steady_clock;
29 using TimeEntry = std::pair<std::string, TimePoint>;
46 auto now()
const {
return Clock::now(); }
54 TickResult tick(std::string timepoint_name,
double threshold = 0.0, std::ostream* os =
nullptr) {
55 auto new_entry =
makeNowTick(std::move(timepoint_name));
61 if (threshold < result.seconds_since_last) {
62 result.recorded =
true;
69 return std::chrono::duration<double>(
end - start).count();
73 if (
times.size() < 2) {
return; }
74 std::ptrdiff_t longest_name = 0;
75 for (
auto& name_and_time :
times) {
76 longest_name = std::max(longest_name, (std::ptrdiff_t)name_and_time.first.size());
79 for (
auto prev =
times.begin(), it = prev; it !=
times.end(); prev = it, ++it) {
81 if (std::next(it) !=
times.end()) {
88 os << std::setw(name_width) << entry.first
105 times.emplace_back(std::move(new_entry));