summaryrefslogtreecommitdiff
path: root/timer.hpp
diff options
context:
space:
mode:
authorJan Huwald <jh@sotun.de>2013-06-04 12:25:32 (GMT)
committerJan Huwald <jh@sotun.de>2013-06-04 12:25:32 (GMT)
commit455a137b7bf8572637097767e4748eb3d9f5ed7a (patch)
tree98607b5c2f2f8a58a8f837614a5fc67c0419ba6d /timer.hpp
parent4bccf8848a3410795ab66d7f615fa5b98417afc6 (diff)
add verbose timer function, replace bitset w/ packed_array
Replacing bitset with packed_array is neccessary to allow parallel access to proximate array cells.
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