From: wolf Date: Thu, 10 Sep 1998 09:27:39 +0000 (+0000) Subject: Clean up timer class. It will still not work correctly for overflows, I assume. X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=98c41e5647dfc3b7f1bcd94a17196cf620723cde;p=dealii-svn.git Clean up timer class. It will still not work correctly for overflows, I assume. git-svn-id: https://svn.dealii.org/trunk@602 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/base/include/base/timer.h b/deal.II/base/include/base/timer.h index 7e6ec5ab2a..4bc94ec2fb 100644 --- a/deal.II/base/include/base/timer.h +++ b/deal.II/base/include/base/timer.h @@ -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; }; diff --git a/deal.II/base/source/timer.cc b/deal.II/base/source/timer.cc index 72c599f7b3..c51d26376e 100644 --- a/deal.II/base/source/timer.cc +++ b/deal.II/base/source/timer.cc @@ -7,20 +7,12 @@ #include -#ifndef TIMER -#define TIMER static_cast(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(clock()) / + CLOCKS_PER_SEC; }; double Timer::stop () { running = false; - double dtime = TIMER / DIVIDE - start_time; + double dtime = (static_cast(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(clock()) / CLOCKS_PER_SEC - start_time; + if (dtime < 0) + overflow++; + + return dtime + full_time(); + } + else + return full_time(); };