[mlpack-git] master: Move timerState to Timers, instead of the static Timer class. (a435e75)
gitdub at big.cc.gt.atl.ga.us
gitdub at big.cc.gt.atl.ga.us
Thu Nov 19 11:35:04 EST 2015
Repository : https://github.com/mlpack/mlpack
On branch : master
Link : https://github.com/mlpack/mlpack/compare/713fa60a06f709bc715c4dd88f6ba585796f73a0...319205b2f3103187c584db302b1a3683aa2fbfdf
>---------------------------------------------------------------
commit a435e75e7115bd0848272e0e12e9a09a3b815dfc
Author: Ryan Curtin <ryan at ratml.org>
Date: Tue Nov 17 17:47:08 2015 -0500
Move timerState to Timers, instead of the static Timer class.
>---------------------------------------------------------------
a435e75e7115bd0848272e0e12e9a09a3b815dfc
src/mlpack/core/util/timers.cpp | 42 ++++++++++++++++++++---------------------
src/mlpack/core/util/timers.hpp | 6 +++---
2 files changed, 23 insertions(+), 25 deletions(-)
diff --git a/src/mlpack/core/util/timers.cpp b/src/mlpack/core/util/timers.cpp
index 4c649b2..b6888fc 100644
--- a/src/mlpack/core/util/timers.cpp
+++ b/src/mlpack/core/util/timers.cpp
@@ -33,17 +33,6 @@ inline void timersub(const timeval* tvp, const timeval* uvp, timeval* vvp)
*/
void Timer::Start(const std::string& name)
{
- if((timerState[name] == 1) && (name != "total_time"))
- {
- std::ostringstream error;
- error << "Timer::Start(): timer '" << name
- << "' has already been " << "started";
-
- throw std::runtime_error(error.str());
- }
-
- timerState[name] = true;
-
CLI::GetSingleton().timer.StartTimer(name);
}
@@ -52,17 +41,6 @@ void Timer::Start(const std::string& name)
*/
void Timer::Stop(const std::string& name)
{
- if((timerState[name] == 0) && (name != "total_time"))
- {
- std::ostringstream error;
- error << "Timer::Stop(): timer '" << name
- << "' has already been " << "stopped";
-
- throw std::runtime_error(error.str());
- }
-
- timerState[name] = false;
-
CLI::GetSingleton().timer.StopTimer(name);
}
@@ -227,6 +205,16 @@ void Timers::GetTime(timeval* tv)
void Timers::StartTimer(const std::string& timerName)
{
+ if ((timerState[timerName] == 1) && (timerName != "total_time"))
+ {
+ std::ostringstream error;
+ error << "Timer::Start(): timer '" << timerName
+ << "' has already been started";
+ throw std::runtime_error(error.str());
+ }
+
+ timerState[timerName] = true;
+
timeval tmp;
tmp.tv_sec = 0;
tmp.tv_usec = 0;
@@ -268,6 +256,16 @@ void Timers::FileTimeToTimeVal(timeval* tv)
void Timers::StopTimer(const std::string& timerName)
{
+ if ((timerState[timerName] == 0) && (timerName != "total_time"))
+ {
+ std::ostringstream error;
+ error << "Timer::Stop(): timer '" << timerName
+ << "' has already been stopped";
+ throw std::runtime_error(error.str());
+ }
+
+ timerState[timerName] = false;
+
timeval delta, b, a = timers[timerName];
GetTime(&b);
diff --git a/src/mlpack/core/util/timers.hpp b/src/mlpack/core/util/timers.hpp
index b5f3db6..d5eb359 100644
--- a/src/mlpack/core/util/timers.hpp
+++ b/src/mlpack/core/util/timers.hpp
@@ -91,9 +91,6 @@ class Timer
* @param name Name of timer to return value of.
*/
static timeval Get(const std::string& name);
-
- private:
- static std::map<std::string, bool> timerState;
};
class Timers
@@ -141,7 +138,10 @@ class Timers
void StopTimer(const std::string& timerName);
private:
+ //! A map of all the timers that are being tracked.
std::map<std::string, timeval> timers;
+ //! A map that contains whether or not each timer is currently running.
+ std::map<std::string, bool> timerState;
void FileTimeToTimeVal(timeval* tv);
void GetTime(timeval* tv);
More information about the mlpack-git
mailing list