NuTo
Numerics Tool
Timer.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <string>
4 #include <chrono>
5 
6 namespace NuTo
7 {
8 class Logger;
9 
11 class Timer
12 {
13 public:
17  Timer(std::string rMsg, bool rShowTime = true);
18 
22  Timer(std::string rMsg, bool rShowTime, Logger& rLogger);
23 
24  Timer(const Timer&) = delete;
25  Timer& operator=(const Timer&) = delete;
26 
28  ~Timer();
29 
30  void Reset();
31 
32  void Reset(std::string rMsg);
33 
34 
36  double GetTimeDifference() const;
37 
38 #ifdef _OPENMP
39  double GetCPUTimeDifference() const;
41 #endif // _OPENMP
42 
43  std::string mMsg;
44  bool mShowTime;
46 
47 #ifdef _OPENMP
48  double mCPUTimeInit;
49 #endif // _OPENMP
50 
51  static constexpr int mMinOutputLength = 90;
52 
53  std::chrono::time_point<std::chrono::system_clock> mWallTimeInit;
54 };
55 }
Timer & operator=(const Timer &)=delete
Logger * mLogger
Definition: Timer.h:45
prints the lifetime of a Timer object on destruction
Definition: Timer.h:11
bool mShowTime
Definition: Timer.h:44
void Reset()
Definition: Timer.cpp:41
static constexpr int mMinOutputLength
Definition: Timer.h:51
~Timer()
dtor, prints the msg and the lifetime
Definition: Timer.cpp:36
std::string mMsg
Definition: Timer.h:43
std::chrono::time_point< std::chrono::system_clock > mWallTimeInit
Definition: Timer.h:53
logger class for redirecting output to different locations/files
Definition: Logger.h:12
Definition: Exception.h:6
Timer(std::string rMsg, bool rShowTime=true)
ctor, saves the current time
Definition: Timer.cpp:14
double GetTimeDifference() const
returns the time from ctor to now in seconds
Definition: Timer.cpp:83