mlpack  master
timers.hpp
Go to the documentation of this file.
1 
13 #ifndef MLPACK_CORE_UTILITIES_TIMERS_HPP
14 #define MLPACK_CORE_UTILITIES_TIMERS_HPP
15 
16 #include <map>
17 #include <string>
18 #include <chrono> // chrono library for cross platform timer calculation
19 
20 #if defined(_WIN32)
21  // uint64_t isn't defined on every windows.
22  #if !defined(HAVE_UINT64_T)
23  #if SIZEOF_UNSIGNED_LONG == 8
24  typedef unsigned long uint64_t;
25  #else
26  typedef unsigned long long uint64_t;
27  #endif // SIZEOF_UNSIGNED_LONG
28  #endif // HAVE_UINT64_T
29 #endif
30 
31 namespace mlpack {
32 
38 class Timer
39 {
40  public:
52  static void Start(const std::string& name);
53 
62  static void Stop(const std::string& name);
63 
69  static std::chrono::microseconds Get(const std::string& name);
70 };
71 
72 class Timers
73 {
74  public:
76  Timers() { }
77 
81  std::map<std::string, std::chrono::microseconds>& GetAllTimers();
82 
88  std::chrono::microseconds GetTimer(const std::string& timerName);
89 
96  void PrintTimer(const std::string& timerName);
97 
106  void StartTimer(const std::string& timerName);
107 
114  void StopTimer(const std::string& timerName);
115 
121  bool GetState(std::string timerName);
122 
123  private:
125  std::map<std::string, std::chrono::microseconds> timers;
127  std::map<std::string, bool> timerState;
129  std::map<std::string, std::chrono::high_resolution_clock::time_point>
131 
132  std::chrono::high_resolution_clock::time_point GetTime();
133 };
134 
135 } // namespace mlpack
136 
137 #endif // MLPACK_CORE_UTILITIES_TIMERS_HPP
std::map< std::string, bool > timerState
A map that contains whether or not each timer is currently running.
Definition: timers.hpp:127
std::map< std::string, std::chrono::microseconds > timers
A map of all the timers that are being tracked.
Definition: timers.hpp:125
Timers()
Nothing to do for the constructor.
Definition: timers.hpp:76
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: binarize.hpp:18
std::map< std::string, std::chrono::high_resolution_clock::time_point > timerStartTime
A map for the starting values of the timers.
Definition: timers.hpp:130
static std::chrono::microseconds Get(const std::string &name)
Get the value of the given timer.
static void Start(const std::string &name)
Start the given timer.
The timer class provides a way for mlpack methods to be timed.
Definition: timers.hpp:38
static void Stop(const std::string &name)
Stop the given timer.
test cpp RESULT_VARIABLE MEX_RESULT_TRASH OUTPUT_VARIABLE MEX_OUTPUT ERROR_VARIABLE MEX_ERROR_TRASH string(REGEX MATCH"Warning: You are using"MEX_WARNING"${MEX_OUTPUT}") if(MEX_WARNING) string(REGEX REPLACE".*using [a-zA-Z]* version \"([0-9.]*)[^\"]*\".*""\\1"OTHER_COMPILER_VERSION"$
Definition: CMakeLists.txt:18