From 80686d4e567bae579ea39e009826a2de92cd4ace Mon Sep 17 00:00:00 2001 From: redpony Date: Wed, 11 Aug 2010 02:37:10 +0000 Subject: major refactor, break bad circular deps git-svn-id: https://ws10smt.googlecode.com/svn/trunk@509 ec762483-ff6d-05da-a07a-a48fb63a330f --- utils/timing_stats.cc | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 utils/timing_stats.cc (limited to 'utils/timing_stats.cc') diff --git a/utils/timing_stats.cc b/utils/timing_stats.cc new file mode 100644 index 00000000..fc8e9df1 --- /dev/null +++ b/utils/timing_stats.cc @@ -0,0 +1,24 @@ +#include "timing_stats.h" + +#include +#include "time.h" //cygwin needs +using namespace std; + +map 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() { + for (map::iterator it = stats.begin(); it != stats.end(); ++it) { + cerr << it->first << ": " << it->second.total_time << " secs (" << it->second.calls << " calls)\n"; + } + stats.clear(); +} + -- cgit v1.2.3