timers.hpp
Go to the documentation of this file.00001
00023 #ifndef __MLPACK_CORE_UTILITIES_TIMERS_HPP
00024 #define __MLPACK_CORE_UTILITIES_TIMERS_HPP
00025
00026 #include <map>
00027 #include <string>
00028
00029 #if defined(__unix__) || defined(__unix)
00030 #include <time.h>
00031 #include <sys/time.h>
00032 #include <unistd.h>
00033 #elif defined(__MACH__) && defined(__APPLE__)
00034 #include <mach/mach_time.h>
00035
00036
00037
00038 #include <time.h>
00039 #include <sys/time.h>
00040 #include <unistd.h>
00041 #elif defined(_WIN32)
00042 #include <windows.h>
00043
00044
00045 #include <winsock.h>
00046
00047
00048 #if !defined(HAVE_UINT64_T)
00049 #if SIZEOF_UNSIGNED_LONG == 8
00050 typedef unsigned long uint64_t;
00051 #else
00052 typedef unsigned long long uint64_t;
00053 #endif // SIZEOF_UNSIGNED_LONG
00054 #endif // HAVE_UINT64_T
00055
00056
00057 #if defined(_MSC_VER) || defined(_MSC_EXTENSIONS)
00058 #define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64
00059 #else
00060 #define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL
00061 #endif // _MSC_VER, _MSC_EXTENSIONS
00062 #else
00063 #error "unknown OS"
00064 #endif
00065
00066 namespace mlpack {
00067
00073 class Timer
00074 {
00075 public:
00086 static void Start(const std::string& name);
00087
00095 static void Stop(const std::string& name);
00096
00102 static timeval Get(const std::string& name);
00103 };
00104
00105 class Timers
00106 {
00107 public:
00109 Timers() { }
00110
00114 std::map<std::string, timeval>& GetAllTimers();
00115
00121 timeval GetTimer(const std::string& timerName);
00122
00129 void PrintTimer(const std::string& timerName);
00130
00139 void StartTimer(const std::string& timerName);
00140
00147 void StopTimer(const std::string& timerName);
00148
00149 private:
00150 std::map<std::string, timeval> timers;
00151
00152 void FileTimeToTimeVal(timeval* tv);
00153 void GetTime(timeval* tv);
00154 };
00155
00156 };
00157
00158 #endif // __MLPACK_CORE_UTILITIES_TIMERS_HPP