Wildmeshing Toolkit
Loading...
Searching...
No Matches
Stopwatch.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <spdlog/common.h>
4#include <chrono>
5#include <type_traits>
7
8namespace wmtk::utils {
9
11{
12public:
13 StopWatch(const std::string& name);
14 StopWatch(const std::string& name, const spdlog::level::level_enum log_level);
15
16 virtual ~StopWatch();
17
18 void start();
19 void stop();
20
21 template <typename T = std::chrono::seconds>
22 int64_t getElapsedTime();
23
24 void log_msg();
25
26
27private:
28 std::string m_name;
29 spdlog::level::level_enum m_log_level = spdlog::level::info;
30 std::chrono::high_resolution_clock::time_point m_start;
31 std::chrono::high_resolution_clock::time_point m_stop;
32
33 bool m_is_running = false;
34};
35
36template <typename T>
37inline int64_t StopWatch::getElapsedTime()
38{
39 auto duration = std::chrono::duration_cast<T>(m_stop - m_start);
40 return duration.count();
41}
42
43} // namespace wmtk::utils
std::chrono::high_resolution_clock::time_point m_stop
Definition Stopwatch.hpp:31
std::chrono::high_resolution_clock::time_point m_start
Definition Stopwatch.hpp:30
spdlog::level::level_enum m_log_level
Definition Stopwatch.hpp:29