]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Clean up timer class. It will still not work correctly for overflows, I assume.
authorwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Thu, 10 Sep 1998 09:27:39 +0000 (09:27 +0000)
committerwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Thu, 10 Sep 1998 09:27:39 +0000 (09:27 +0000)
git-svn-id: https://svn.dealii.org/trunk@602 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/base/include/base/timer.h
deal.II/base/source/timer.cc

index 7e6ec5ab2a2b8b545671acfd9b0ae3fa563e1104..4bc94ec2fb0cc51305fa0af41add511a137d3d97 100644 (file)
@@ -58,10 +58,29 @@ public:
     double operator() ();
 
   private:
-    
+
+                                    /**
+                                     * Value of the user time when #start#
+                                     * was called the last time or when the
+                                     * object was created and no #stop# was
+                                     * issued in between.
+                                     */
     double              start_time;
+
+                                    /**
+                                     * Accumulated time for all previous
+                                     * #start#/#stop# cycles. The time for
+                                     * the present cycle is not included.
+                                     */
     double              cumulative_time;
-    static const double overtime;
+
+                                    /**
+                                     * Number of times that the counter
+                                     * had an overflow. We need to adjust the
+                                     * total time by this number times the
+                                     * number of seconds after which an
+                                     * overflow occurs.
+                                     */
     unsigned int        overflow;
 
                                     /**
@@ -69,7 +88,14 @@ public:
                                      * running.
                                      */
     bool                running;
-    
+
+                                    /**
+                                     * Return #cumulative_time# plus the
+                                     * number of overflows times the number
+                                     * of seconds per overflow. Do not include
+                                     * the time since the last overflow
+                                     * occured.
+                                     */
     double full_time() const;
 };
 
index 72c599f7b3cfcbe0920d2d7e18855d8c3f24846e..c51d26376ecc66e5ec9c8f12f7445a9e57c32cce 100644 (file)
@@ -7,20 +7,12 @@
 #include <sys/time.h>
 
 
-#ifndef TIMER
-#define TIMER static_cast<double>(clock())
-#endif
 
-#ifndef DIVIDE
-#define DIVIDE CLOCKS_PER_SEC
-#endif
-#ifndef OVER_TIME
-#define OVER_TIME 4294967296./DIVIDE
-#endif
+// maybe use times() instead of clock()?
 
 
+const double overtime = 4294967296./CLOCKS_PER_SEC;
 
-const double Timer::overtime = OVER_TIME;
 
 
 Timer::Timer()
@@ -33,14 +25,16 @@ Timer::Timer()
 void Timer::start () {
   running    = true;
   overflow   = 0;
-  start_time = TIMER / DIVIDE;
+  start_time = static_cast<double>(clock()) /
+              CLOCKS_PER_SEC;
 };
 
 
 
 double Timer::stop () {
   running = false;
-  double dtime =  TIMER / DIVIDE - start_time;
+  double dtime =  (static_cast<double>(clock()) / CLOCKS_PER_SEC -
+                  start_time);
   if (dtime < 0) {
     overflow++;
   };
@@ -52,16 +46,16 @@ double Timer::stop () {
 
 
 double Timer::operator() () {
-  if (running) {
-    const double dtime =  TIMER / DIVIDE - start_time;
-    if (dtime < 0) {
-      overflow++;
-    };
-    
-    return dtime + full_time();
-  };
-  
-  return full_time();
+  if (running)
+    {
+      const double dtime =  static_cast<double>(clock()) / CLOCKS_PER_SEC - start_time;
+      if (dtime < 0)
+       overflow++;
+
+      return dtime + full_time();
+    }
+  else
+    return full_time();
 };
 
 

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.