[mlpack-svn] r11865 - mlpack/trunk/src/mlpack/core/util
fastlab-svn at coffeetalk-1.cc.gatech.edu
fastlab-svn at coffeetalk-1.cc.gatech.edu
Wed Mar 14 16:23:53 EDT 2012
Author: rcurtin
Date: 2012-03-14 16:23:52 -0400 (Wed, 14 Mar 2012)
New Revision: 11865
Modified:
mlpack/trunk/src/mlpack/core/util/timers.cpp
mlpack/trunk/src/mlpack/core/util/timers.hpp
Log:
Make timers multi-run.
Modified: mlpack/trunk/src/mlpack/core/util/timers.cpp
===================================================================
--- mlpack/trunk/src/mlpack/core/util/timers.cpp 2012-03-14 19:22:13 UTC (rev 11864)
+++ mlpack/trunk/src/mlpack/core/util/timers.cpp 2012-03-14 20:23:52 UTC (rev 11865)
@@ -115,6 +115,18 @@
#else
FileTimeToTimeVal(&tmp);
#endif
+
+ // Check to see if the timer already exists. If it does, we'll subtract the
+ // old value.
+ if (timers.count(timerName) == 1)
+ {
+ timeval tmpDelta;
+
+ timersub(&tmp, &timers[timerName], &tmpDelta);
+
+ tmp = tmpDelta;
+ }
+
timers[timerName] = tmp;
}
@@ -136,15 +148,15 @@
tv->tv_usec = (long) (ptime % 1000000UL);
}
-inline void timersub(const timeval* tvp, const timeval* uvp, timeval * vvp)
+inline void timersub(const timeval* tvp, const timeval* uvp, timeval* vvp)
{
- vvp->tv_sec = tvp->tv_sec - uvp->tv_sec;
- vvp->tv_usec = tvp->tv_usec - uvp->tv_usec;
- if (vvp->tv_usec < 0)
- {
- --vvp->tv_sec;
- vvp->tv_usec += 1000000;
- }
+ vvp->tv_sec = tvp->tv_sec - uvp->tv_sec;
+ vvp->tv_usec = tvp->tv_usec - uvp->tv_usec;
+ if (vvp->tv_usec < 0)
+ {
+ --vvp->tv_sec;
+ vvp->tv_usec += 1000000;
+ }
}
#endif // _WIN32
Modified: mlpack/trunk/src/mlpack/core/util/timers.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core/util/timers.hpp 2012-03-14 19:22:13 UTC (rev 11864)
+++ mlpack/trunk/src/mlpack/core/util/timers.hpp 2012-03-14 20:23:52 UTC (rev 11865)
@@ -34,8 +34,13 @@
{
public:
/**
- * Start the given timer.
+ * Start the given timer. If a timer is started, then stopped, then
+ * re-started, then re-stopped, the final value of the timer is the length of
+ * both runs -- that is, MLPACK timers are additive for each time they are
+ * run, and do not reset.
*
+ * @note Undefined behavior will occur if a timer is started twice.
+ *
* @param name Name of timer to be started.
*/
static void Start(const std::string& name);
@@ -43,6 +48,8 @@
/**
* Stop the given timer.
*
+ * @note Undefined behavior will occur if a timer is started twice.
+ *
* @param name Name of timer to be stopped.
*/
static void Stop(const std::string& name);
@@ -83,7 +90,9 @@
/**
* Initializes a timer, available like a normal value specified on
- * the command line. Timers are of type timval
+ * the command line. Timers are of type timeval. If a timer is started, then
+ * stopped, then re-started, then stopped, the final timer value will be the
+ * length of both runs of the timer.
*
* @param timerName The name of the timer in question.
*/
More information about the mlpack-svn
mailing list