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
68d39c70
Commit
68d39c70
authored
Sep 16, 2017
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Changed TIME_THIS() to use std::chrono::high_resolution_clock
parent
0f8b227e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
61 deletions
+20
-61
time_this.h
dlib/time_this.h
+20
-61
No files found.
dlib/time_this.h
View file @
68d39c70
...
...
@@ -4,74 +4,33 @@
#define DLIB_TIME_THIs_
#include
"platform.h"
#include
<chrono>
#ifndef WIN32
#include <sys/times.h>
#include <limits.h>
#include <unistd.h>
#include <iostream>
// ----------------------------------------------------------------------------------------
#define TIME_THIS_TO(_tt_op,_tt_out) \
{ \
clock_t _tt_start, _tt_end; \
tms _tt_timesbuf; \
_tt_start = times(&_tt_timesbuf); \
_tt_op; \
_tt_end = times(&_tt_timesbuf); \
long _tt_ticks = sysconf(_SC_CLK_TCK); \
if ((double)(_tt_end-_tt_start)/(double)_tt_ticks < 1) \
{ \
_tt_out << "\ntime: " \
<< (int)(1000*((double)(_tt_end-_tt_start)/(double)_tt_ticks)) << "ms\n"; \
} \
else \
{ \
_tt_out << "\ntime: " \
<< (double)(_tt_end-_tt_start)/(double)_tt_ticks << "sec\n"; \
} \
} \
#define TIME_THIS_TO(_tt_op,_tt_out) \
{ \
auto _tt_start = std::chrono::high_resolution_clock::now(); \
{_tt_op;} \
auto _tt_stop = std::chrono::high_resolution_clock::now(); \
auto _tt_thetime = _tt_stop-_tt_start; \
using std::chrono::duration_cast; \
using std::chrono::duration; \
if (_tt_thetime >= std::chrono::minutes(1)) \
_tt_out << "\ntime: " << duration_cast<duration<double>>(_tt_thetime).count() << "min\n"; \
else if (_tt_thetime >= std::chrono::seconds(1)) \
_tt_out << "\ntime: " << duration_cast<duration<double>>(_tt_thetime).count() << "sec\n"; \
else if (_tt_thetime >= std::chrono::milliseconds(1)) \
_tt_out << "\ntime: " << duration_cast<duration<double,std::milli>>(_tt_thetime).count() << "ms\n"; \
else if (_tt_thetime >= std::chrono::microseconds(1)) \
_tt_out << "\ntime: " << duration_cast<duration<double,std::micro>>(_tt_thetime).count() << "us\n"; \
else \
_tt_out << "\ntime: " << duration_cast<duration<double,std::nano>>(_tt_thetime).count() << "ns\n"; \
}
#define TIME_THIS(_tt_op) TIME_THIS_TO(_tt_op,std::cout)
// ----------------------------------------------------------------------------------------
#endif
#ifdef WIN32
#include "windows_magic.h"
#include <windows.h> // for GetTickCount()
#include <iostream>
// ----------------------------------------------------------------------------------------
#define TIME_THIS_TO(_tt_op,_tt_out) \
{ \
unsigned long _tt_count = GetTickCount(); \
_tt_op; \
_tt_count = GetTickCount() - _tt_count; \
if (_tt_count < 1000) \
{ \
_tt_out << "\ntime: " << _tt_count << "ms\n"; \
} \
else \
{ \
_tt_out << "\ntime: " << static_cast<double>(_tt_count)/1000 << "sec\n"; \
} \
} \
#define TIME_THIS(_tt_op) TIME_THIS_TO(_tt_op,std::cout)
// ----------------------------------------------------------------------------------------
#endif
#endif // DLIB_TIME_THIs_
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