summaryrefslogtreecommitdiff
path: root/timer.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'timer.hpp')
-rw-r--r--timer.hpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/timer.hpp b/timer.hpp
new file mode 100644
index 0000000..8d413b3
--- /dev/null
+++ b/timer.hpp
@@ -0,0 +1,35 @@
+#pragma once
+
+#include <sys/time.h>
+#include <string>
+#include <iostream>
+#include <boost/optional.hpp>
+
+struct PerfPrinter {
+ timeval start;
+ boost::optional<std::string> msg;
+
+ PerfPrinter(boost::optional<std::string> msg) : msg(msg) {
+ if (msg)
+ std::cerr << "\r\033[K"
+ << *msg
+ << std::flush;
+ gettimeofday(&start,NULL);
+ }
+
+ ~PerfPrinter() {
+ if (msg)
+ std::cerr << "\r\033[K"
+ << *msg
+ << ": "
+ << diff()
+ << " s"
+ << std::endl;
+ }
+
+ double diff() {
+ timeval stop;
+ gettimeofday(&stop,NULL);
+ return (stop.tv_sec + stop.tv_usec/1000000.0) - (start.tv_sec + start.tv_usec/1000000.0);
+ }
+};
contact: Jan Huwald // Impressum