14#include <lagrange/Logger.h>
21using timestamp_type = std::chrono::time_point<std::chrono::steady_clock>;
23inline void get_timestamp(timestamp_type* t)
25 *t = std::chrono::steady_clock::now();
28inline timestamp_type get_timestamp()
30 return std::chrono::steady_clock::now();
33inline double timestamp_diff_in_seconds(timestamp_type start, timestamp_type end)
35 std::chrono::duration<double> p = end - start;
39inline double timestamp_diff_in_seconds(timestamp_type start)
41 std::chrono::duration<double> p = get_timestamp() - start;
59 std::string prefix =
"",
61 spdlog::level::level_enum level = spdlog::level::debug)
62 : m_prefix(std::move(prefix))
63 , m_logger(log ? log : &
logger())
70 void tick() { m_start_time = get_timestamp(); }
79 double tock(
const std::string name =
"")
81 auto end_time = get_timestamp();
82 auto duration = timestamp_diff_in_seconds(m_start_time, end_time);
83 m_logger->log(m_level,
"{}{} time: {} (s)", m_prefix, name, duration);
90 spdlog::level::level_enum m_level = spdlog::level::debug;
91 timestamp_type m_start_time;
110 spdlog::level::level_enum level = spdlog::level::debug)
111 : m_timer(std::make_unique<
VerboseTimer>(prefix, log, level))
130 std::unique_ptr<VerboseTimer> m_timer;
142 void tick() { m_start_time = get_timestamp(); }
149 double tock(
const std::string name =
"")
152 auto end_time = get_timestamp();
153 return timestamp_diff_in_seconds(m_start_time, end_time);
157 timestamp_type m_start_time;
169 void reset() { m_start = m_last = get_timestamp(); }
179 m_last = get_timestamp();
180 return timestamp_diff_in_seconds(last, m_last);
188 double total() {
return timestamp_diff_in_seconds(m_start); }
191 timestamp_type m_start;
192 timestamp_type m_last;
Similar to a VerboseTimer, but uses RAII to call tick()/tock().
Definition: timing.h:98
ScopedTimer(std::string prefix, spdlog::logger *log=nullptr, spdlog::level::level_enum level=spdlog::level::debug)
Constructs a new instance.
Definition: timing.h:107
A timer that keeps track of a total time as well as intervals.
Definition: timing.h:164
double interval()
Returns current interval time (in seconds) and resets interval to now.
Definition: timing.h:176
double total()
Returns total time.
Definition: timing.h:188
void reset()
Starts/restarts the timer.
Definition: timing.h:169
A timer that does not print after tock()
Definition: timing.h:137
void tick()
Starts the timer.
Definition: timing.h:142
double tock(const std::string name="")
Stops the timer.
Definition: timing.h:149
Creates a verbose timer that prints after tock().
Definition: timing.h:49
VerboseTimer(std::string prefix="", spdlog::logger *log=nullptr, spdlog::level::level_enum level=spdlog::level::debug)
Constructs a new instance.
Definition: timing.h:58
void tick()
Starts the timer.
Definition: timing.h:70
double tock(const std::string name="")
Stops the timer.
Definition: timing.h:79
LA_CORE_API spdlog::logger & logger()
Retrieves the current logger.
Definition: Logger.cpp:40
Main namespace for Lagrange.
Definition: AABBIGL.h:30