76 std::chrono::high_resolution_clock::time_point tstart{};
77 std::string convertHR(
double t)
const;
83 : name(in_name), running(false), total_time_ms(0) {
89 std::cout << name <<
": T = " <<
reading_str() <<
"\n";
98 tstart = std::chrono::high_resolution_clock::now();
110 total_time_ms += current_time;
134 std::chrono::high_resolution_clock::time_point tcurrent =
135 std::chrono::high_resolution_clock::now();
138 std::chrono::duration_cast<std::chrono::microseconds>(tcurrent - tstart)
141 return ((
double)duration) * 1.0e-3;
162inline std::string ChronoTimer::convertHR(
double t)
const
172 }
else if (t < 60000) {
175 }
else if (t < 3600000) {
183 std::stringstream ss;
184 ss << std::fixed << std::setprecision(2) << ot;
185 return ss.str() +
" " + un;
Class that uses std::chrono to easily time code.
Definition ChronoTimer.hpp:35
std::string lap_reading_str() const
Current lap elapsed time as a human-readable string.
Definition ChronoTimer.hpp:157
void start()
Starts (or resumes) timing.
Definition ChronoTimer.hpp:93
ChronoTimer(std::string_view in_name="")
Constructs and immediately starts the timer. If in_name is non-empty, prints elapsed time to stdout o...
Definition ChronoTimer.hpp:82
double lap_reading_ms() const
Elapsed time in milliseconds for the current lap only (since last start()).
Definition ChronoTimer.hpp:126
~ChronoTimer()
Prints elapsed time if a name was given at construction.
Definition ChronoTimer.hpp:87
void restart()
Equivalent to reset() followed by start().
Definition ChronoTimer.hpp:114
std::string reading_str() const
Total elapsed time as a human-readable string (e.g., "1.56 s", "2.10 hours").
Definition ChronoTimer.hpp:153
void stop()
Pauses timing and accumulates elapsed time into the running total.
Definition ChronoTimer.hpp:102
void reset()
Clears all accumulated time and stops the timer. Must call start() to resume.
Definition ChronoTimer.hpp:120
double reading_ms() const
Total elapsed time in milliseconds (accumulated laps + current lap if running).
Definition ChronoTimer.hpp:145
In-out (timers, profilers, and read/write data)
Definition ChronoTimer.hpp:9