Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
dlib
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
钟尚武
dlib
Commits
895d7874
Commit
895d7874
authored
7 years ago
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Changed the timing code to use the C++11 high resolution clock and
atomics. This makes the timing code a lot more precise.
parent
13442ec1
master
v19.17
v19.16
v19.15
v19.14
v19.13
v19.12
v19.11
v19.10
v19.9
v19.8
No related merge requests found
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
11 deletions
+12
-11
timing.h
dlib/timing.h
+12
-11
No files found.
dlib/timing.h
View file @
895d7874
...
...
@@ -3,7 +3,8 @@
#ifndef DLIB_TImING_Hh_
#define DLIB_TImING_Hh_
#include "misc_api.h"
#include <chrono>
#include <atomic>
#include <cstring>
#include "string.h"
...
...
@@ -76,9 +77,9 @@ namespace dlib
const
int
TIME_SLOTS
=
500
;
const
int
NAME_LENGTH
=
40
;
inline
uint64
*
time_buf
()
inline
std
::
atomic
<
uint64_t
>
*
time_buf
()
{
static
uint64
buf
[
TIME_SLOTS
]
=
{
0
}
;
static
std
::
atomic
<
uint64_t
>
buf
[
TIME_SLOTS
]
;
return
buf
;
}
...
...
@@ -96,26 +97,26 @@ namespace dlib
return
buf
[
i
];
}
inline
timestamper
&
ts
()
inline
uint64_t
ts
()
{
static
timestamper
ts_
;
return
ts_
;
using
namespace
std
::
chrono
;
return
duration_cast
<
duration
<
double
,
std
::
nano
>>
(
high_resolution_clock
::
now
().
time_since_epoch
()).
count
()
;
}
inline
void
start
(
int
i
)
inline
void
start
(
int
i
)
{
time_buf
()[
i
]
-=
ts
()
.
get_timestamp
()
;
time_buf
()[
i
]
-=
ts
();
}
inline
void
start
(
int
i
,
const
char
*
name
)
{
time_buf
()[
i
]
-=
ts
()
.
get_timestamp
()
;
time_buf
()[
i
]
-=
ts
();
name_buf
(
i
,
name
);
}
inline
void
stop
(
int
i
)
{
time_buf
()[
i
]
+=
ts
()
.
get_timestamp
()
;
time_buf
()[
i
]
+=
ts
();
}
inline
void
print
()
...
...
@@ -140,7 +141,7 @@ namespace dlib
{
if
(
time_buf
()[
i
]
!=
0
)
{
double
time
=
time_buf
()[
i
]
/
1000
.
0
;
double
time
=
time_buf
()[
i
]
/
1000
.
0
/
1000
.
0
;
string
name
;
// Check if the name buffer is empty. Use the name it contains if it isn't.
if
(
name_buf
(
i
,
""
)[
0
]
!=
'\0'
)
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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