summaryrefslogtreecommitdiff
path: root/utils/timing_stats.cc
blob: dc90bf531d235a3237d0c27761d636629617d027 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include "timing_stats.h"

#include <iostream>
#include "time.h" //cygwin needs

#include "verbose.h"

using namespace std;

map<string, TimerInfo> Timer::stats;

Timer::Timer(const string& timername) : start_t(clock()), cur(stats[timername]) {}

Timer::~Timer() {
  ++cur.calls;
  const clock_t end_t = clock();
  const double elapsed = (end_t - start_t) / 1000000.0;
  cur.total_time += elapsed;
}

void Timer::Summarize() {
  if (!SILENT) {
    for (map<string, TimerInfo>::iterator it = stats.begin(); it != stats.end(); ++it) {
      cerr << it->first << ": " << it->second.total_time << " secs (" << it->second.calls << " calls)\n";
    }
  }
  stats.clear();
}