Cuberite
A lightweight, fast and extensible game server for Minecraft
Stopwatch.h
Go to the documentation of this file.
1 
2 // Stopwatch.h
3 
4 // Implements the cStopwatch class that measures and logs time between its creation and destruction
5 
6 
7 
8 
9 
10 #pragma once
11 
12 
13 
14 
15 
17 {
18 public:
19  cStopwatch(const AString & a_Name):
20  m_Name(a_Name),
21  m_StartTime(std::chrono::high_resolution_clock::now())
22  {
23  }
24 
26  {
27  auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - m_StartTime).count();
28  LOG("Stopwatch: %s took %.03f sec", m_Name, static_cast<double>(duration) / 1000);
29  }
30 
31 protected:
33  std::chrono::high_resolution_clock::time_point m_StartTime;
34 };
35 
36 
37 
38 
void LOG(std::string_view a_Format, const Args &... args)
Definition: LoggerSimple.h:55
std::string AString
Definition: StringUtils.h:11
Definition: FastNBT.h:132
~cStopwatch()
Definition: Stopwatch.h:25
cStopwatch(const AString &a_Name)
Definition: Stopwatch.h:19
AString m_Name
Definition: Stopwatch.h:32
std::chrono::high_resolution_clock::time_point m_StartTime
Definition: Stopwatch.h:33