[mlpack-svn] r10456 - mlpack/trunk/src/mlpack/core/utilities

fastlab-svn at coffeetalk-1.cc.gatech.edu fastlab-svn at coffeetalk-1.cc.gatech.edu
Tue Nov 29 17:07:38 EST 2011


Author: rcurtin
Date: 2011-11-29 17:07:38 -0500 (Tue, 29 Nov 2011)
New Revision: 10456

Modified:
   mlpack/trunk/src/mlpack/core/utilities/timers.cpp
   mlpack/trunk/src/mlpack/core/utilities/timers.hpp
Log:
Update timers.hpp and timers.cpp to conform to formatting guidelines (and fix a
syntax error!).


Modified: mlpack/trunk/src/mlpack/core/utilities/timers.cpp
===================================================================
--- mlpack/trunk/src/mlpack/core/utilities/timers.cpp	2011-11-29 21:13:40 UTC (rev 10455)
+++ mlpack/trunk/src/mlpack/core/utilities/timers.cpp	2011-11-29 22:07:38 UTC (rev 10456)
@@ -1,3 +1,9 @@
+/**
+ * @file timers.cpp
+ * @author Matthew Amidon
+ *
+ * Implementation of timers.
+ */
 #include "timers.hpp"
 #include "../io/cli.hpp"
 #include "../io/log.hpp"
@@ -9,62 +15,76 @@
 
 std::map<std::string, timeval> Timers::timers;
 
-std::map<std::string, timeval> Timers::GetAllTimers() {
+std::map<std::string, timeval> Timers::GetAllTimers()
+{
   return timers;
 }
 
-timeval Timers::GetTimer(const char* timerName) {
+timeval Timers::GetTimer(const char* timerName)
+{
   std::string name(timerName);
   return timers[name];
 }
 
-void Timers::PrintTimer(const char* timerName) {
+void Timers::PrintTimer(const char* timerName)
+{
   std::string name=timerName;
   timeval& t = timers[name];
   Log::Info << t.tv_sec << "." << std::setw(6) << std::setfill('0')
-    << t.tv_usec << "s";
+      << t.tv_usec << "s";
 
-  //Also output convenient day/hr/min/sec.
+  // Also output convenient day/hr/min/sec.
+  int days = t.tv_sec / 86400; // Integer division rounds down.
+  int hours = (t.tv_sec % 86400) / 3600;
+  int minutes = (t.tv_sec % 3600) / 60;
+  int seconds = (t.tv_sec % 60);
+  // No output if it didn't even take a minute.
+  if (!(days == 0 && hours == 0 && minutes == 0))
+  {
+    bool output = false; // Denotes if we have output anything yet.
+    Log::Info << "(";
 
-  int days = t.tv_sec/86400; //Integerdivisionroundsdown.
-  int hours = (t.tv_sec%86400) / 3600;
-  int minutes = (t.tv_sec%3600) / 60;
-  int seconds = (t.tv_sec%60);
-  //No output if it didn't even take a minute.
-  if ( !(days == 0 && hours == 0 && minutes == 0) ){
-    bool output = false;//Denotesifwehaveoutputanythingyet.
-    Log::Info << "(";
-    //Only output units if they have nonzero values (yes, a bit tedious).
-    if ( days>0 ){
+    // Only output units if they have nonzero values (yes, a bit tedious).
+    if (days > 0)
+    {
       Log::Info << days << "days";
       output = true;
     }
-    if ( hours>0 ){
-      if( output )
+
+    if (hours > 0)
+    {
+      if (output)
         Log::Info << ",";
-      Log::Info << hours <<"hrs";
+      Log::Info << hours << "hrs";
       output = true;
     }
-    if ( minutes>0 ){
-      if ( output )
+
+    if (minutes > 0)
+    {
+      if (output)
         Log::Info << ",";
       Log::Info << minutes << "mins";
       output = true;
     }
-    if ( seconds>0 ){
-      if ( output )
+
+    if (seconds > 0)
+    {
+      if (output)
         Log::Info << ",";
-      Log::Info << seconds << "." << std::setw(1) << (t.tv_usec/100000) <<
-        "secs";
+      Log::Info << seconds << "." << std::setw(1) << (t.tv_usec / 100000) <<
+          "secs";
       output = true;
     }
-    Log::Info<<")";
-  }  
+
+    Log::Info << ")";
+  }
+
   Log::Info << std::endl;
 }
 
-void Timers::StartTimer(const char* timerName) {
-  //Don't want to actually document the timer
+void Timers::StartTimer(const char* timerName)
+{
+  // Convert the name to std::string.
   std::string name(timerName);
   timeval tmp;
 
@@ -79,7 +99,8 @@
   timers[name] = tmp;
 }
 
-void Timers::StopTimer(const char* timerName) {
+void Timers::StopTimer(const char* timerName)
+{
   std::string name(timerName);
   timeval delta, b, a = timers[name];
 
@@ -88,25 +109,26 @@
 #else
   FileTimeToTimeVal(&b);
 #endif
-  //Calculate the delta time
-  timersub(&b,&a,&delta);
+  // Calculate the delta time.
+  timersub(&b, &a, &delta);
   timers[name] = delta;
 }
 
 #ifdef _WIN32
-void Timers::FileTimeToTimeVal(timeval* tv) {
+void Timers::FileTimeToTimeVal(timeval* tv)
+{
   FILETIME ftime;
   uint64_t ptime = 0;
-  //Acquire the file time
+  // Acquire the file time.
   GetSystemTimeAsFileTime(&ftime);
-  //Now convert FILETIME to timeval
+  // Now convert FILETIME to timeval.
   ptime |= ftime.dwHighDateTime;
   ptime = ptime << 32;
   ptime |= ftime.dwLowDateTime;
-  ptime /= 10; 
+  ptime /= 10;
   ptime -= DELTA_EPOC_IN_MICROSECONDS;
- 
-  tv.tv_sec=(long)(ptime/1000000UL);
-  tv.tv_usec = (long)(ptime%1000000UL)
+
+  tv.tv_sec = (long) (ptime / 1000000UL);
+  tv.tv_usec = (long) (ptime % 1000000UL);
 }
-#endif //WIN32
+#endif // _WIN32

Modified: mlpack/trunk/src/mlpack/core/utilities/timers.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core/utilities/timers.hpp	2011-11-29 21:13:40 UTC (rev 10455)
+++ mlpack/trunk/src/mlpack/core/utilities/timers.hpp	2011-11-29 22:07:38 UTC (rev 10456)
@@ -1,5 +1,11 @@
-#ifndef MLPACK_TIMERS_H
-#define MLPACK_TIMERS_H
+/**
+ * @file timers.hpp
+ * @author Matthew Amidon
+ *
+ * Timers for MLPACK.
+ */
+#ifndef __MLPACK_CORE_UTILITIES_TIMERS_HPP
+#define __MLPACK_CORE_UTILITIES_TIMERS_HPP
 
 #include <map>
 #include <string>
@@ -19,53 +25,55 @@
 
 namespace mlpack {
 
-class Timers {
+class Timers
+{
  public:
- /*
-  * Returns a copy of all the timers used via this interface.
-  */
+  /**
+   * Returns a copy of all the timers used via this interface.
+   */
   static std::map<std::string, timeval> GetAllTimers();
 
- /*
-  * Returns a copy of the timer specified.
-  *
-  * @param timerName The name of the timer in question.
-  */
+  /**
+   * Returns a copy of the timer specified.
+   *
+   * @param timerName The name of the timer in question.
+   */
   static timeval GetTimer(const char* timerName);
 
- /*
-  * Prints the specified timer.  If it took longer than a minute to complete
-  * the timer will be displayed in days, hours, and minutes as well.
-  *
-  * @param timerName The name of the timer in question.
-  */
+  /**
+   * Prints the specified timer.  If it took longer than a minute to complete
+   * the timer will be displayed in days, hours, and minutes as well.
+   *
+   * @param timerName The name of the timer in question.
+   */
   static void PrintTimer(const char* timerName);
 
- /*
-  * Initializes a timer, available like a normal value specified on
-  * the command line.  Timers are of type timval
-  *
-  * @param timerName The name of the timer in question.
-  */
+  /**
+   * Initializes a timer, available like a normal value specified on
+   * the command line.  Timers are of type timval
+   *
+   * @param timerName The name of the timer in question.
+   */
   static void StartTimer(const char* timerName);
 
- /*
-  * Halts the timer, and replaces it's value with
-  * the delta time from it's start
-  *
-  * @param timerName The name of the timer in question.
-  */
+  /**
+   * Halts the timer, and replaces it's value with
+   * the delta time from it's start
+   *
+   * @param timerName The name of the timer in question.
+   */
   static void StopTimer(const char* timerName);
+
  private:
   static std::map<std::string, timeval> timers;
 
   void FileTimeToTimeVal(timeval* tv);
 
-  //Don't want any instances floating around.
+  // Don't want any instances floating around.
   Timers();
   ~Timers();
 };
 
-}; //namespace mlpack
+}; // namespace mlpack
 
-#endif //MLPACK_TIMERS_H
+#endif // __MLPACK_CORE_UTILITIES_TIMERS_HPP




More information about the mlpack-svn mailing list