Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
wolf
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mobile_robotics
wolf_projects
wolf_lib
wolf
Commits
be16205f
Commit
be16205f
authored
8 years ago
by
artivis
Committed by
Jeremie Deray
8 years ago
Browse files
Options
Downloads
Patches
Plain Diff
add timer
parent
c5757dc4
No related branches found
No related tags found
1 merge request
!90
[WIP] ProcessorBase multi-threading
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/timer.h
+98
-0
98 additions, 0 deletions
src/timer.h
with
98 additions
and
0 deletions
src/timer.h
0 → 100644
+
98
−
0
View file @
be16205f
#ifndef WOLF_TIMER_H_
#define WOLF_TIMER_H_
#include
<chrono>
namespace
wolf
{
namespace
details
{
using
std
::
chrono
::
hours
;
using
std
::
chrono
::
minutes
;
using
std
::
chrono
::
seconds
;
using
std
::
chrono
::
milliseconds
;
using
std
::
chrono
::
microseconds
;
using
std
::
chrono
::
nanoseconds
;
template
<
typename
_Clock
,
typename
_Dur
>
using
time_point
=
std
::
chrono
::
time_point
<
_Clock
,
_Dur
>
;
using
wolf_time_unit
=
nanoseconds
;
using
wolf_clock_t
=
std
::
chrono
::
_V2
::
high_resolution_clock
;
}
// namespace details
/**
* @brief Timer. A tic-toc timer.
*
* Mesure the elapsed time between construction - or tic() -
* and toc(). The elapsed time is expressed in unit.
*
* @param unit. The time unit.
* @see unit
*/
template
<
typename
unit
>
class
Timer
{
public:
/**
* @brief Timer. Launch the timer.
*/
Timer
()
:
start_
(
now
())
{
}
/**
* @brief ~Timer. Default desctructor.
*/
~
Timer
()
=
default
;
/**
* @brief tic. Reset the timer.
*/
void
tic
()
{
start_
=
now
();
}
/**
* @brief toc. Return this elapsed time since construction or last tic().
* @return double. The elapsed time.
* @see tic()
*/
template
<
typename
T
=
int64_t
>
T
toc
()
{
return
static_cast
<
T
>
(
cast_d
(
now
()
-
start_
).
count
());
}
protected
:
details
::
time_point
<
details
::
wolf_clock_t
,
unit
>
start_
;
template
<
typename
...
Args
>
auto
cast_d
(
Args
&&
...
args
)
->
decltype
(
std
::
chrono
::
duration_cast
<
unit
>
(
std
::
forward
<
Args
>
(
args
)...))
{
return
std
::
chrono
::
duration_cast
<
unit
>
(
std
::
forward
<
Args
>
(
args
)...);
}
template
<
typename
...
Args
>
auto
cast
(
Args
&&
...
args
)
->
decltype
(
std
::
chrono
::
time_point_cast
<
unit
>
(
std
::
forward
<
Args
>
(
args
)...))
{
return
std
::
chrono
::
time_point_cast
<
unit
>
(
std
::
forward
<
Args
>
(
args
)...);
}
auto
now
()
->
decltype
(
std
::
declval
<
Timer
<
unit
>>
().
cast
(
details
::
wolf_clock_t
::
now
()))
{
return
cast
(
std
::
chrono
::
system_clock
::
now
());
}
};
using
timer_secs
=
Timer
<
details
::
seconds
>
;
using
timer_msecs
=
Timer
<
details
::
milliseconds
>
;
using
timer_usecs
=
Timer
<
details
::
microseconds
>
;
using
timer_nsecs
=
Timer
<
details
::
microseconds
>
;
}
// namespace wolf
#endif // WOLF_TIMER_H_
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment