From 9eb76ebd3e970c3e37ce95ec6e21242a3b0ee0e4 Mon Sep 17 00:00:00 2001 From: Bjoern Brandenburg Date: Tue, 7 Aug 2012 11:03:56 +0200 Subject: Add benchmarking helper class CPUClock is useful for repeatedly measuring how long some piece of code executes. --- native/src/cpu_time.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'native/src/cpu_time.cpp') 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 @@ #include #include +#include + #include "cpu_time.h" @@ -47,3 +49,31 @@ double get_cpu_usage(void) } #endif + + +std::ostream& operator<<(std::ostream &os, const CPUClock &clock) +{ + if (clock.get_function()) + os << clock.get_function() << "::"; + os << clock.get_name() + << ": total=" << clock.get_total() * 1000 << "ms " + << "last=" << clock.get_last() * 1000 << "ms " + << "average=" << clock.get_average() * 1000 << "ms " + << "count=" << clock.get_count(); + return os; +} + +char *strip_types(const char* pretty_func) +{ + char *copy = strdup(pretty_func); + + char *start = strchr(copy, ' '); + char *end = strchr(copy, '('); + + if (start) + copy = start + 1; + if (end) + *end = '\0'; + + return copy; +} -- cgit v1.2.2