39 ChronoTimer(std::string_view in_name =
"",
bool print =
true);
77 std::chrono::high_resolution_clock::time_point tstart{};
80 std::string convertHR(
double t)
const;
85 : name(in_name), m_print(print), running(false), total_time_ms(0) {
95 std::cout << name <<
": T = " <<
reading_str() <<
"\n";
105 tstart = std::chrono::high_resolution_clock::now();
117 total_time_ms += current_time;
141 std::chrono::high_resolution_clock::time_point tcurrent =
142 std::chrono::high_resolution_clock::now();
145 std::chrono::duration_cast<std::chrono::microseconds>(tcurrent - tstart)
148 return ((
double)duration) * 1.0e-3;
169inline std::string ChronoTimer::convertHR(
double t)
const
179 }
else if (t < 60000) {
182 }
else if (t < 3600000) {
190 std::stringstream ss;
191 ss << std::fixed << std::setprecision(2) << ot;
192 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:164
void start()
Starts (or resumes) timing.
Definition ChronoTimer.hpp:100
double lap_reading_ms() const
Elapsed time in milliseconds for the current lap only (since last start()).
Definition ChronoTimer.hpp:133
~ChronoTimer()
Prints elapsed time if a name was given at construction.
Definition ChronoTimer.hpp:89
void restart()
Equivalent to reset() followed by start().
Definition ChronoTimer.hpp:121
ChronoTimer(std::string_view in_name="", bool print=true)
Constructs and immediately starts the timer. If print is true (default), prints elapsed time to stdou...
Definition ChronoTimer.hpp:84
std::string reading_str() const
Total elapsed time as a human-readable string (e.g., "1.56 s", "2.10 hours").
Definition ChronoTimer.hpp:160
void stop()
Pauses timing and accumulates elapsed time into the running total.
Definition ChronoTimer.hpp:109
void reset()
Clears all accumulated time and stops the timer. Must call start() to resume.
Definition ChronoTimer.hpp:127
double reading_ms() const
Total elapsed time in milliseconds (accumulated laps + current lap if running).
Definition ChronoTimer.hpp:152
In-out (timers, profilers, and read/write data)
Definition ChronoTimer.hpp:9