Commit 53d67d88 authored by Joseph Mirabel's avatar Joseph Mirabel Committed by Joseph Mirabel
Browse files

Add possibility to benchmark scope

parent caf207c6
......@@ -91,6 +91,13 @@ namespace hpp
class HPP_UTIL_DLLAPI TimeCounter
{
public:
struct Scope {
Scope (TimeCounter& t) : tc(t) { t.start(); }
~Scope () { tc.stop(); }
TimeCounter& tc;
};
typedef boost::posix_time::ptime ptime;
typedef boost::posix_time::time_duration time_duration;
......@@ -120,6 +127,9 @@ namespace hpp
# if HPP_ENABLE_BENCHMARK
# define HPP_DEFINE_TIMECOUNTER(name) \
::hpp::debug::TimeCounter _##name##_timecounter_ (#name)
# define HPP_SCOPE_TIMECOUNTER(name) \
::hpp::debug::TimeCounter::Scope _##name##_scopetimecounter_ \
(_##name##_timecounter_)
# define HPP_START_TIMECOUNTER(name) \
_##name##_timecounter_.start ()
# define HPP_STOP_TIMECOUNTER(name) \
......@@ -150,6 +160,7 @@ namespace hpp
# else // HPP_ENABLE_BENCHMARK
# define HPP_DEFINE_TIMECOUNTER(name) \
struct _##name##_EndWithSemiColon_{}
# define HPP_SCOPE_TIMECOUNTER(name)
# define HPP_START_TIMECOUNTER(name)
# define HPP_STOP_TIMECOUNTER(name)
# define HPP_DISPLAY_LAST_TIMECOUNTER(name)
......
......@@ -36,11 +36,13 @@ void f(const int extra)
}
HPP_DEFINE_TIMECOUNTER(testCounter);
HPP_DEFINE_TIMECOUNTER(testCounter2);
int run_test ()
{
int N = 10;
logging.benchmark = Channel ("BENCHMARK", boost::assign::list_of<Output*> (&logging.console));
for (int i = 0; i < 10; ++i) {
for (int i = 0; i < N; ++i) {
HPP_START_TIMECOUNTER(testCounter);
int k = 1 + (std::rand()%10);
// std::cout << k << std::endl;
......@@ -49,6 +51,14 @@ int run_test ()
HPP_DISPLAY_LAST_TIMECOUNTER(testCounter);
}
HPP_DISPLAY_TIMECOUNTER(testCounter);
for (int i = 0; i < N; ++i) {
HPP_SCOPE_TIMECOUNTER(testCounter2);
int k = 1 + (std::rand()%10);
// std::cout << k << std::endl;
f(k);
HPP_DISPLAY_LAST_TIMECOUNTER(testCounter2);
}
HPP_DISPLAY_TIMECOUNTER(testCounter2);
return 0;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment