Skip to content
Snippets Groups Projects
Commit fcc5f2e6 authored by René Fritze's avatar René Fritze
Browse files

loop timer changes

parent f886cfe6
No related branches found
No related tags found
No related merge requests found
...@@ -344,24 +344,63 @@ Profiler& profiler() ...@@ -344,24 +344,63 @@ Profiler& profiler()
} }
namespace Stuff { namespace Stuff {
struct IdentityWeights
{
double apply(const double to_weigh, const int /*current*/, const int /*max*/)
{
return to_weigh;
}
};
struct LinearWeights
{
double apply(const double to_weigh, const int current, const int max)
{
return to_weigh / (current / double(max));
}
};
struct QuadraticWeights
{
double apply(const double to_weigh, const int current, const int max)
{
return to_weigh / std::pow(current / double(max), 2.0);
}
};
struct ProgressiveWeights
{
const int prog_;
ProgressiveWeights(const int prog)
: prog_(prog)
{
}
double apply(const double to_weigh, const int /*current*/, const int /*max*/)
{
return to_weigh * prog_;
}
};
//! helper class to estimate time needed to complete a loop with given counter //! helper class to estimate time needed to complete a loop with given counter
template <class CounterType, class OutputStreamType> template <class CounterType, class OutputStreamType, class WeightType = IdentityWeights>
class LoopTimer class LoopTimer
{ {
typedef LoopTimer<CounterType, OutputStreamType> ThisType; typedef LoopTimer<CounterType, OutputStreamType, WeightType> ThisType;
CounterType& counter_; CounterType& counter_;
const int iteration_count_; const int iteration_count_;
int iteration_; int iteration_;
OutputStreamType& output_stream_; OutputStreamType& output_stream_;
WeightType weight_;
MovingAverage avg_time_per_iteration_; MovingAverage avg_time_per_iteration_;
Dune::ExecutionTimer step_timer_; Dune::ExecutionTimer step_timer_;
public: public:
LoopTimer(CounterType& counter, const int iteration_count, OutputStreamType& output_stream = std::cout) LoopTimer(CounterType& counter, const int iteration_count, OutputStreamType& output_stream = std::cout,
WeightType weight = WeightType())
: counter_(counter) : counter_(counter)
, iteration_count_(iteration_count) , iteration_count_(iteration_count)
, iteration_(0) , iteration_(0)
, output_stream_(output_stream) , output_stream_(output_stream)
, weight_(weight)
{ {
step_timer_.start(); step_timer_.start();
} }
...@@ -370,12 +409,14 @@ public: ...@@ -370,12 +409,14 @@ public:
{ {
++iteration_; ++iteration_;
step_timer_.end(); step_timer_.end();
avg_time_per_iteration_ += std::abs(step_timer_.read()); avg_time_per_iteration_ += weight_.apply(std::abs(step_timer_.read()), iteration_, iteration_count_);
long remaining_steps = iteration_count_ - iteration_; long remaining_steps = iteration_count_ - iteration_;
double remaining_seconds = remaining_steps * double(avg_time_per_iteration_); double remaining_seconds = remaining_steps * double(avg_time_per_iteration_);
boost::posix_time::time_duration diff(0, 0, remaining_seconds, 0); boost::posix_time::time_duration diff(0, 0, remaining_seconds, 0);
output_stream_ << boost::format("\n---\n Total Time remaining: %s (%f %%)\n---\n") boost::posix_time::ptime target = boost::posix_time::second_clock::local_time();
% boost::posix_time::to_simple_string(diff) target += diff;
output_stream_ << boost::format("\n---\n Total Time remaining: %s -- %s (%f %%)\n---\n")
% boost::posix_time::to_simple_string(diff) % boost::posix_time::to_simple_string(target)
% (100 * (remaining_steps / double(iteration_count_))) % (100 * (remaining_steps / double(iteration_count_)))
<< std::endl; << std::endl;
step_timer_.start(); step_timer_.start();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment