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
bddbcb7f
Commit
bddbcb7f
authored
Jul 05, 2016
by
Joseph Mirabel
Committed by
Joseph Mirabel
Sep 14, 2016
Browse files
Add min and max in TimeCounter
parent
4d040a21
Changes
4
Hide whitespace changes
Inline
Side-by-side
include/hpp/util/timer.hh
View file @
bddbcb7f
...
...
@@ -90,6 +90,8 @@ namespace hpp
time_duration
last
();
void
reset
();
time_duration
min
()
const
;
time_duration
max
()
const
;
time_duration
mean
()
const
;
time_duration
totalTime
()
const
;
...
...
@@ -98,7 +100,7 @@ namespace hpp
private:
std
::
string
n_
;
unsigned
long
c_
;
time_duration
t_
,
last_
;
time_duration
t_
,
last_
,
min_
,
max_
;
ptime
s_
;
};
...
...
src/timer.cc
View file @
bddbcb7f
...
...
@@ -94,7 +94,8 @@ namespace hpp
}
TimeCounter
::
TimeCounter
(
const
std
::
string
&
name
)
:
n_
(
name
),
c_
(
0
),
t_
(
0
,
0
,
0
,
0
)
n_
(
name
),
c_
(
0
),
t_
(
0
,
0
,
0
,
0
),
min_
(
boost
::
date_time
::
pos_infin
),
max_
(
0
,
0
,
0
,
0
)
{}
void
TimeCounter
::
start
()
...
...
@@ -105,6 +106,8 @@ namespace hpp
TimeCounter
::
time_duration
TimeCounter
::
stop
()
{
last_
=
boost
::
posix_time
::
microsec_clock
::
universal_time
()
-
s_
;
min_
=
std
::
min
(
last_
,
min_
);
max_
=
std
::
max
(
last_
,
max_
);
t_
+=
last_
;
++
c_
;
return
last_
;
...
...
@@ -117,8 +120,20 @@ namespace hpp
void
TimeCounter
::
reset
()
{
t_
=
TimeCounter
::
time_duration
(
0
,
0
,
0
,
0
);
t_
=
time_duration
(
0
,
0
,
0
,
0
);
c_
=
0
;
min_
=
time_duration
(
boost
::
date_time
::
pos_infin
);
max_
=
time_duration
(
0
,
0
,
0
,
0
);
}
TimeCounter
::
time_duration
TimeCounter
::
min
()
const
{
return
min_
;
}
TimeCounter
::
time_duration
TimeCounter
::
max
()
const
{
return
max_
;
}
TimeCounter
::
time_duration
TimeCounter
::
mean
()
const
...
...
@@ -133,8 +148,13 @@ namespace hpp
std
::
ostream
&
TimeCounter
::
print
(
std
::
ostream
&
os
)
const
{
return
os
<<
"Time Counter "
<<
n_
<<
": "
<<
c_
<<
", "
<<
totalTime
()
<<
", "
<<
mean
();
return
os
<<
"Time Counter "
<<
n_
<<
": "
<<
c_
<<
", "
<<
totalTime
()
<<
", [ "
<<
min
()
<<
", "
<<
mean
()
<<
", "
<<
max
()
<<
"]"
;
}
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
TimeCounter
&
tc
)
...
...
tests/CMakeLists.txt
View file @
bddbcb7f
...
...
@@ -39,3 +39,4 @@ DEFINE_TEST(assertion hpp-util)
DEFINE_TEST
(
exception hpp-util
)
DEFINE_TEST
(
exception-factory hpp-util
)
DEFINE_TEST
(
debug hpp-util
)
DEFINE_TEST
(
timer hpp-util
)
tests/timer.cc
0 → 100644
View file @
bddbcb7f
// Copyright (c) 2016, Joseph Mirabel
// Authors: Joseph Mirabel (joseph.mirabel@laas.fr)
//
// This file is part of hpp-util.
// hpp-util is free software: you can redistribute it
// and/or modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation, either version
// 3 of the License, or (at your option) any later version.
//
// hpp-util is distributed in the hope that it will be
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Lesser Public License for more details. You should have
// received a copy of the GNU Lesser General Public License along with
// hpp-util. If not, see <http://www.gnu.org/licenses/>.
#include
<boost/assign/list_of.hpp>
#include
<cstdlib>
#include
"config.h"
#define HPP_ENABLE_BENCHMARK 1
#include
<hpp/util/timer.hh>
#include
"common.hh"
using
namespace
hpp
::
debug
;
// the function f() does some time-consuming work
void
f
(
const
int
extra
)
{
volatile
double
d
=
0
;
for
(
int
n
=
0
;
n
<
extra
*
1000
;
++
n
)
for
(
int
m
=
0
;
m
<
1000
;
++
m
)
d
+=
d
*
n
*
m
;
}
HPP_DEFINE_TIMECOUNTER
(
testCounter
);
int
run_test
()
{
logging
.
benchmark
=
Channel
(
"BENCHMARK"
,
boost
::
assign
::
list_of
<
Output
*>
(
&
logging
.
console
));
for
(
int
i
=
0
;
i
<
10
;
++
i
)
{
HPP_START_TIMECOUNTER
(
testCounter
);
int
k
=
1
+
(
std
::
rand
()
%
10
);
// std::cout << k << std::endl;
f
(
k
);
HPP_STOP_TIMECOUNTER
(
testCounter
);
HPP_DISPLAY_LAST_TIMECOUNTER
(
testCounter
);
}
HPP_DISPLAY_TIMECOUNTER
(
testCounter
);
return
0
;
}
GENERATE_TEST
()
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