Wildmeshing Toolkit
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>
6 #include <wmtk/utils/Logger.hpp>
7 
8 namespace wmtk::utils {
9 
10 class StopWatch
11 {
12 public:
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 
27 private:
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 
36 template <typename T>
37 inline 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
int64_t getElapsedTime()
Definition: Stopwatch.hpp:37
StopWatch(const std::string &name)
Definition: Stopwatch.cpp:9
spdlog::level::level_enum m_log_level
Definition: Stopwatch.hpp:29