Commit in projects/lcdd/trunk on MAIN | |||
include/lcdd/util/TimeUtil.hh | +35 | -1 | 3110 -> 3111 |
src/lcdd/util/TimeUtil.cc | +3 | added 3111 | |
+38 | -1 |
Add time utilities for performance benchmarking.
--- projects/lcdd/trunk/include/lcdd/util/TimeUtil.hh 2014-05-08 00:13:45 UTC (rev 3110) +++ projects/lcdd/trunk/include/lcdd/util/TimeUtil.hh 2014-05-08 21:13:38 UTC (rev 3111) @@ -1,10 +1,15 @@
#ifndef lcdd_util_TimeUtil_hh_
-#define lcdd_util_TimeUtil_hh_
+#define lcdd_util_TimeUtil_hh_ 1
#include <sys/time.h>
+#include <string> +#include <map> +
class TimeUtil {
+ static std::map<std::string, long> _timerMap; +
public: static long getNanoTime() {
@@ -12,6 +17,35 @@
clock_gettime(CLOCK_REALTIME, &ts); return ts.tv_nsec; }
+ + static bool haveTimer(const std::string& name) { + return _timerMap.count(name) != 0; + } + + static void startTimer(const std::string& name) { + _timerMap[name] = getNanoTime(); + } + + static long stopTimer(const std::string& name) { + _timerMap[name] = getNanoTime() - _timerMap[name]; + return _timerMap[name]; + } + + static void addTime(const std::string& name, long nanos) { + _timerMap[name] += nanos; + } + + static void createTimer(const std::string& name) { + _timerMap[name] = 0; + } + + static long getTime(const std::string& name) { + return _timerMap[name]; + } + + static void clearTimers() { + _timerMap.clear(); + }
}; #endif
--- projects/lcdd/trunk/src/lcdd/util/TimeUtil.cc (rev 0) +++ projects/lcdd/trunk/src/lcdd/util/TimeUtil.cc 2014-05-08 21:13:38 UTC (rev 3111) @@ -0,0 +1,3 @@
+#include "lcdd/util/TimeUtil.hh" + +std::map<std::string, long> TimeUtil::_timerMap = std::map<std::string, long>();
Use REPLY-ALL to reply to list
To unsubscribe from the LCDET-SVN list, click the following link:
https://listserv.slac.stanford.edu/cgi-bin/wa?SUBED1=LCDET-SVN&A=1