Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Guilhem Saurel
hpp-util
Commits
53d67d88
Commit
53d67d88
authored
Jul 27, 2017
by
Joseph Mirabel
Committed by
Joseph Mirabel
Jul 27, 2017
Browse files
Add possibility to benchmark scope
parent
caf207c6
Changes
2
Hide whitespace changes
Inline
Side-by-side
include/hpp/util/timer.hh
View file @
53d67d88
...
...
@@ -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)
...
...
tests/timer.cc
View file @
53d67d88
...
...
@@ -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
;
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment