avoid cacheing the history to eliminate performance penalty

release/4.3a0
Yong-Dian Jian 2012-02-15 23:49:46 +00:00
parent b96b03a733
commit b4216b325b
2 changed files with 6 additions and 10 deletions

View File

@ -42,13 +42,13 @@ std::string timingPrefix;
void TimingOutline::add(size_t usecs) { void TimingOutline::add(size_t usecs) {
t_ += usecs; t_ += usecs;
tIt_ += usecs; tIt_ += usecs;
t2_ += (double(usecs)/1000000.0)*(double(usecs)/1000000.0);
++ n_; ++ n_;
history_.push_back(usecs);
} }
/* ************************************************************************* */ /* ************************************************************************* */
TimingOutline::TimingOutline(const std::string& label) : TimingOutline::TimingOutline(const std::string& label) :
t_(0), tIt_(0), tMax_(0), tMin_(0), n_(0), label_(label), timerActive_(false) {} t_(0), t2_(0.0), tIt_(0), tMax_(0), tMin_(0), n_(0), label_(label), timerActive_(false) {}
/* ************************************************************************* */ /* ************************************************************************* */
size_t TimingOutline::time() const { size_t TimingOutline::time() const {
@ -88,18 +88,13 @@ void TimingOutline::print(const std::string& outline) const {
void TimingOutline::print2(const std::string& outline) const { void TimingOutline::print2(const std::string& outline) const {
const int w1 = 24, w2 = 3, w3 = 6, precision = 3; const int w1 = 24, w2 = 3, w3 = 8, precision = 3;
const double selfTotal = double(t_)/(1000000.0), const double selfTotal = double(t_)/(1000000.0),
selfMean = selfTotal/double(n_); selfMean = selfTotal/double(n_);
// const double childMean = double(time())/(1000000.0*n_); // const double childMean = double(time())/(1000000.0*n_);
// compute standard deviation // compute standard deviation
double acc = 0.0; const double selfStd = sqrt(t2_/double(n_) - selfMean*selfMean);
BOOST_FOREACH(const size_t &t, history_) {
const double tmp = double(t)/1000000.0 - selfMean ;
acc += (tmp*tmp);
}
const double selfStd = sqrt(acc);
const std::string label = label_ + ": " ; const std::string label = label_ + ": " ;
if ( n_ == 0 ) { if ( n_ == 0 ) {

View File

@ -30,12 +30,13 @@ extern boost::weak_ptr<TimingOutline> timingCurrent;
class TimingOutline { class TimingOutline {
protected: protected:
size_t t_; size_t t_;
double t2_ ; /* cache the \sum t_i^2 */
size_t tIt_; size_t tIt_;
size_t tMax_; size_t tMax_;
size_t tMin_; size_t tMin_;
size_t n_; size_t n_;
std::string label_; std::string label_;
std::vector<size_t> history_;
boost::weak_ptr<TimingOutline> parent_; boost::weak_ptr<TimingOutline> parent_;
std::vector<boost::shared_ptr<TimingOutline> > children_; std::vector<boost::shared_ptr<TimingOutline> > children_;
struct timeval t0_; struct timeval t0_;