Commit bddbcb7f authored by Joseph Mirabel's avatar Joseph Mirabel Committed by Joseph Mirabel
Browse files

Add min and max in TimeCounter

parent 4d040a21
...@@ -90,6 +90,8 @@ namespace hpp ...@@ -90,6 +90,8 @@ namespace hpp
time_duration last (); time_duration last ();
void reset (); void reset ();
time_duration min () const;
time_duration max () const;
time_duration mean () const; time_duration mean () const;
time_duration totalTime () const; time_duration totalTime () const;
...@@ -98,7 +100,7 @@ namespace hpp ...@@ -98,7 +100,7 @@ namespace hpp
private: private:
std::string n_; std::string n_;
unsigned long c_; unsigned long c_;
time_duration t_, last_; time_duration t_, last_, min_, max_;
ptime s_; ptime s_;
}; };
......
...@@ -94,7 +94,8 @@ namespace hpp ...@@ -94,7 +94,8 @@ namespace hpp
} }
TimeCounter::TimeCounter (const std::string& name) : TimeCounter::TimeCounter (const std::string& name) :
n_ (name), c_ (0), t_ (0,0,0,0) n_ (name), c_ (0), t_ (0,0,0,0),
min_ (boost::date_time::pos_infin), max_ (0,0,0,0)
{} {}
void TimeCounter::start () void TimeCounter::start ()
...@@ -105,6 +106,8 @@ namespace hpp ...@@ -105,6 +106,8 @@ namespace hpp
TimeCounter::time_duration TimeCounter::stop () TimeCounter::time_duration TimeCounter::stop ()
{ {
last_ = boost::posix_time::microsec_clock::universal_time () - s_; last_ = boost::posix_time::microsec_clock::universal_time () - s_;
min_ = std::min(last_, min_);
max_ = std::max(last_, max_);
t_ += last_; t_ += last_;
++c_; ++c_;
return last_; return last_;
...@@ -117,8 +120,20 @@ namespace hpp ...@@ -117,8 +120,20 @@ namespace hpp
void TimeCounter::reset () void TimeCounter::reset ()
{ {
t_ = TimeCounter::time_duration (0,0,0,0); t_ = time_duration (0,0,0,0);
c_ = 0; c_ = 0;
min_ = time_duration(boost::date_time::pos_infin);
max_ = time_duration(0,0,0,0);
}
TimeCounter::time_duration TimeCounter::min () const
{
return min_;
}
TimeCounter::time_duration TimeCounter::max () const
{
return max_;
} }
TimeCounter::time_duration TimeCounter::mean () const TimeCounter::time_duration TimeCounter::mean () const
...@@ -133,8 +148,13 @@ namespace hpp ...@@ -133,8 +148,13 @@ namespace hpp
std::ostream& TimeCounter::print (std::ostream& os) const std::ostream& TimeCounter::print (std::ostream& os) const
{ {
return os << "Time Counter " << n_ << ": " return os << "Time Counter " << n_
<< c_ << ", " << totalTime () << ", " << mean (); << ": " << c_
<< ", " << totalTime ()
<< ", [ " << min ()
<< ", " << mean ()
<< ", " << max () << "]"
;
} }
std::ostream& operator<< (std::ostream& os, const TimeCounter& tc) std::ostream& operator<< (std::ostream& os, const TimeCounter& tc)
......
...@@ -39,3 +39,4 @@ DEFINE_TEST(assertion hpp-util) ...@@ -39,3 +39,4 @@ DEFINE_TEST(assertion hpp-util)
DEFINE_TEST(exception hpp-util) DEFINE_TEST(exception hpp-util)
DEFINE_TEST(exception-factory hpp-util) DEFINE_TEST(exception-factory hpp-util)
DEFINE_TEST(debug hpp-util) DEFINE_TEST(debug hpp-util)
DEFINE_TEST(timer hpp-util)
// Copyright (c) 2016, Joseph Mirabel
// Authors: Joseph Mirabel (joseph.mirabel@laas.fr)
//
// This file is part of hpp-util.
// hpp-util is free software: you can redistribute it
// and/or modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation, either version
// 3 of the License, or (at your option) any later version.
//
// hpp-util is distributed in the hope that it will be
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Lesser Public License for more details. You should have
// received a copy of the GNU Lesser General Public License along with
// hpp-util. If not, see <http://www.gnu.org/licenses/>.
#include <boost/assign/list_of.hpp>
#include <cstdlib>
#include "config.h"
#define HPP_ENABLE_BENCHMARK 1
#include <hpp/util/timer.hh>
#include "common.hh"
using namespace hpp::debug;
// the function f() does some time-consuming work
void f(const int extra)
{
volatile double d = 0;
for(int n=0; n<extra * 1000; ++n)
for(int m=0; m<1000; ++m)
d += d*n*m;
}
HPP_DEFINE_TIMECOUNTER(testCounter);
int run_test ()
{
logging.benchmark = Channel ("BENCHMARK", boost::assign::list_of<Output*> (&logging.console));
for (int i = 0; i < 10; ++i) {
HPP_START_TIMECOUNTER(testCounter);
int k = 1 + (std::rand()%10);
// std::cout << k << std::endl;
f(k);
HPP_STOP_TIMECOUNTER(testCounter);
HPP_DISPLAY_LAST_TIMECOUNTER(testCounter);
}
HPP_DISPLAY_TIMECOUNTER(testCounter);
return 0;
}
GENERATE_TEST ()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment