MLPACK
1.0.4
|
00001 00022 #ifndef __MLPACK_CORE_UTILITIES_TIMERS_HPP 00023 #define __MLPACK_CORE_UTILITIES_TIMERS_HPP 00024 00025 #include <map> 00026 #include <string> 00027 00028 #ifndef _WIN32 00029 #include <sys/time.h> //linux 00030 #else 00031 #include <winsock.h> //timeval on windows 00032 #include <windows.h> //GetSystemTimeAsFileTime on windows 00033 //gettimeofday has no equivalent will need to write extra code for that. 00034 #if defined(_MSC_VER) || defined(_MSC_EXTENSIONS) 00035 #define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64 00036 #else 00037 #define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL 00038 #endif 00039 #endif //_WIN32 00040 00041 namespace mlpack { 00042 00048 class Timer 00049 { 00050 public: 00061 static void Start(const std::string& name); 00062 00070 static void Stop(const std::string& name); 00071 00077 static timeval Get(const std::string& name); 00078 }; 00079 00080 class Timers 00081 { 00082 public: 00084 Timers() { } 00085 00089 std::map<std::string, timeval>& GetAllTimers(); 00090 00096 timeval GetTimer(const std::string& timerName); 00097 00104 void PrintTimer(const std::string& timerName); 00105 00114 void StartTimer(const std::string& timerName); 00115 00122 void StopTimer(const std::string& timerName); 00123 00124 private: 00125 std::map<std::string, timeval> timers; 00126 00127 void FileTimeToTimeVal(timeval* tv); 00128 }; 00129 00130 }; // namespace mlpack 00131 00132 #endif // __MLPACK_CORE_UTILITIES_TIMERS_HPP