aboutsummaryrefslogtreecommitdiffstats
path: root/native/src/cpu_time.cpp
diff options
context:
space:
mode:
authorBjoern Brandenburg <bbb@mpi-sws.org>2012-08-07 05:03:56 -0400
committerBjoern Brandenburg <bbb@mpi-sws.org>2013-02-12 06:49:39 -0500
commit9eb76ebd3e970c3e37ce95ec6e21242a3b0ee0e4 (patch)
treeec68455719f33fb94420a3b00dfa8020109eb255 /native/src/cpu_time.cpp
parent4b07d5bcd33e4b0433d4b91f9268a54399df676b (diff)
Add benchmarking helper class
CPUClock is useful for repeatedly measuring how long some piece of code executes.
Diffstat (limited to 'native/src/cpu_time.cpp')
-rw-r--r--native/src/cpu_time.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/native/src/cpu_time.cpp b/native/src/cpu_time.cpp
index d003f22..8dde662 100644
--- a/native/src/cpu_time.cpp
+++ b/native/src/cpu_time.cpp
@@ -3,6 +3,8 @@
3#include <sys/time.h> 3#include <sys/time.h>
4#include <sys/resource.h> 4#include <sys/resource.h>
5 5
6#include <cstring>
7
6#include "cpu_time.h" 8#include "cpu_time.h"
7 9
8 10
@@ -47,3 +49,31 @@ double get_cpu_usage(void)
47} 49}
48 50
49#endif 51#endif
52
53
54std::ostream& operator<<(std::ostream &os, const CPUClock &clock)
55{
56 if (clock.get_function())
57 os << clock.get_function() << "::";
58 os << clock.get_name()
59 << ": total=" << clock.get_total() * 1000 << "ms "
60 << "last=" << clock.get_last() * 1000 << "ms "
61 << "average=" << clock.get_average() * 1000 << "ms "
62 << "count=" << clock.get_count();
63 return os;
64}
65
66char *strip_types(const char* pretty_func)
67{
68 char *copy = strdup(pretty_func);
69
70 char *start = strchr(copy, ' ');
71 char *end = strchr(copy, '(');
72
73 if (start)
74 copy = start + 1;
75 if (end)
76 *end = '\0';
77
78 return copy;
79}