From 410f27abeae78c3c0255184f706bf1c6eef47b75 Mon Sep 17 00:00:00 2001 From: Mark Woolrich <woolrich@fmrib.ox.ac.uk> Date: Thu, 1 Feb 2001 16:03:35 +0000 Subject: [PATCH] *** empty log message *** --- time_tracer.h | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/time_tracer.h b/time_tracer.h index a0d77af..aea4a50 100644 --- a/time_tracer.h +++ b/time_tracer.h @@ -22,11 +22,11 @@ namespace Utilities{ public: TimingFunction(const char * pstr): str(pstr), - time_taken(0.0), + time_taken(0), times_called(0) {} - class comparer + class comparer_name { public: bool operator()(const TimingFunction* t1, const TimingFunction* t2) const @@ -35,10 +35,20 @@ namespace Utilities{ } }; + class comparer_time_taken + { + public: + bool operator()(const TimingFunction* t1, const TimingFunction* t2) const + { + return t1->time_taken > t2->time_taken; + } + }; + void start() {start_time = clock();} void end() {time_taken += clock()-start_time; times_called++;} - friend comparer; + friend comparer_name; + friend comparer_time_taken; friend ostream& operator<<(ostream& ostr, const TimingFunction* t); protected: @@ -57,9 +67,9 @@ namespace Utilities{ { ostr << "<tr><td>" << t->str; ostr.setf(0, ios::floatfield); - ostr << "<td align=center>" << t->time_taken/CLOCKS_PER_SEC; + ostr << "<td align=center>" << float(t->time_taken)/CLOCKS_PER_SEC; ostr.setf(ios::scientific, ios::floatfield); - ostr << "<td align=center>" << t->times_called << "<td align=center>" << (t->time_taken/t->times_called)/CLOCKS_PER_SEC; + ostr << "<td align=center>" << t->times_called << "<td align=center>" << (t->time_taken/float(t->times_called))/CLOCKS_PER_SEC; ostr << "</tr>"; return ostr; } @@ -83,7 +93,7 @@ namespace Utilities{ { // see if already in list: timingFunction = new TimingFunction(str); - set<TimingFunction*, TimingFunction::comparer>::iterator it = timingFunctions.find(timingFunction); + set<TimingFunction*, TimingFunction::comparer_name>::iterator it = timingFunctions.find(timingFunction); if(it== timingFunctions.end()) { timingFunctions.insert(timingFunction); @@ -112,11 +122,13 @@ namespace Utilities{ static void dump_times(const string& dir) { + multiset<TimingFunction*, TimingFunction::comparer_time_taken> timingFunctionsByTimeTaken(timingFunctions.begin(), timingFunctions.end()); + ofstream out; out.open((dir + "/timings.html").c_str(), ios::out); out << "<HTML><TITLE>Tracer Timings</TITLE><BODY><table border=3 cellspacing=5>" << endl; out << "<tr><td>Function<td align=center>Total Time(secs)<td align=center>Num of calls<td align=center>Time per call(secs)</tr>" << endl; - copy(timingFunctions.begin(), timingFunctions.end(), ostream_iterator<TimingFunction*>(out, "\n")); + copy(timingFunctionsByTimeTaken.begin(), timingFunctionsByTimeTaken.end(), ostream_iterator<TimingFunction*>(out, "\n")); out << "</table></BODY></HTML>" << endl; out.close(); } @@ -128,7 +140,7 @@ namespace Utilities{ static bool debug; static bool timingon; static unsigned int pad; - static set<TimingFunction*, TimingFunction::comparer> timingFunctions; + static set<TimingFunction*, TimingFunction::comparer_name> timingFunctions; string tmp; TimingFunction* timingFunction; -- GitLab