Skip to content
Snippets Groups Projects

[cleanup] Remove old code in Dune::Timer

Merged Carsten Gräser requested to merge feature/cleanup-timer into master
All threads resolved!
1 file
+ 5
31
Compare changes
  • Side-by-side
  • Inline
  • 28cebf2a
    `Dune::Timer` includes two alternative implementations
    for measuring time. Historically one was based on `getrusage()`
    and the other one on `std::clock()`. The former was the default
    and the latter could be enabled by defining a macro. Both in fact
    measured the time spend computing by the process.
    
    In `fa43f4bf` the default code path was changed from
    `getrusage()` to `std::chrono::high_resolution_clock::now()`
    while `std::clock()` could still be enabled by the macro.
    This was in fact a breaking change because the new default
    version measures the elapsed real time.
    
    This patch removed the non-default version based on `std::clock` because:
    
    * The breaking change happened almost 11 years so one can consider the
      new behavior the established 'correct' version.
    * The macro switch was neither documented nor tested.
    * Setting the macro manually in user code is error prone.
    * Both versions do completely different things leading to
      different measurements. It's not even clear that one
      produces larger numbers in general:
      `std::clock` adds up time spend computing in all threads of the
      process. Thus time in concurrent threads is added up, while
      the time a thread is sleeping is not counted.
    
    There a minor grain of salt: The documentation still documented
    the old behaviour and instead of 'fixing' the code this patch
    adjusts the documentation to established reality.
+ 5
31
@@ -5,13 +5,7 @@
#ifndef DUNE_TIMER_HH
#define DUNE_TIMER_HH
#ifndef TIMER_USE_STD_CLOCK
// headers for std::chrono
#include <chrono>
#else
// headers for std::clock
#include <ctime>
#endif
namespace Dune {
@@ -26,18 +20,12 @@ namespace Dune {
/** \brief A simple stop watch
This class reports the elapsed user-time, i.e. time spent computing,
after the last call to Timer::reset(). The results are seconds and
fractional seconds. Note that the resolution of the timing depends
on your OS kernel which should be somewhere in the millisecond range.
The class is basically a wrapper for the libc-function getrusage()
\warning In a multi-threading situation, this class does NOT return wall-time!
Instead, the run time for all threads will be added up.
For example, if you have four threads running in parallel taking one second each,
then the Timer class will return an elapsed time of four seconds.
This class reports the elapsed real time, i.e. time elapsed
after Timer::reset(). It does not measure the time spent computing,
i.e. time spend in concurrent threads is not added up while
time measurements include the time elapsed while sleeping.
The class is basically a wrapper around std::chrono::high_resolution_clock::now().
*/
class Timer
{
@@ -117,19 +105,6 @@ namespace Dune {
double storedLastElapsed_;
#ifdef TIMER_USE_STD_CLOCK
void rawReset() noexcept
{
cstart = std::clock();
}
double rawElapsed () const noexcept
{
return (std::clock()-cstart) / static_cast<double>(CLOCKS_PER_SEC);
}
std::clock_t cstart;
#else
void rawReset() noexcept
{
cstart = std::chrono::high_resolution_clock::now();
@@ -143,7 +118,6 @@ namespace Dune {
}
std::chrono::high_resolution_clock::time_point cstart;
#endif
}; // end class Timer
/** @} end documentation */
Loading