Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dlib
Commits
68d39c70
"tests/git@developer.sourcefind.cn:OpenDAS/dgl.git" did not exist on "3f891b64b7b51902c39353e3c1cf164331f7b6eb"
Commit
68d39c70
authored
Sep 15, 2017
by
Davis King
Browse files
Changed TIME_THIS() to use std::chrono::high_resolution_clock
parent
0f8b227e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
61 deletions
+20
-61
dlib/time_this.h
dlib/time_this.h
+20
-61
No files found.
dlib/time_this.h
View file @
68d39c70
...
@@ -4,74 +4,33 @@
...
@@ -4,74 +4,33 @@
#define DLIB_TIME_THIs_
#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) \
#define TIME_THIS_TO(_tt_op,_tt_out) \
{ \
{ \
clock_t _tt_start, _tt_end; \
auto _tt_start = std::chrono::high_resolution_clock::now(); \
tms _tt_timesbuf; \
{_tt_op;} \
_tt_start = times(&_tt_timesbuf); \
auto _tt_stop = std::chrono::high_resolution_clock::now(); \
_tt_op; \
auto _tt_thetime = _tt_stop-_tt_start; \
_tt_end = times(&_tt_timesbuf); \
using std::chrono::duration_cast; \
long _tt_ticks = sysconf(_SC_CLK_TCK); \
using std::chrono::duration; \
if ((double)(_tt_end-_tt_start)/(double)_tt_ticks < 1) \
if (_tt_thetime >= std::chrono::minutes(1)) \
{ \
_tt_out << "\ntime: " << duration_cast<duration<double>>(_tt_thetime).count() << "min\n"; \
_tt_out << "\ntime: " \
else if (_tt_thetime >= std::chrono::seconds(1)) \
<< (int)(1000*((double)(_tt_end-_tt_start)/(double)_tt_ticks)) << "ms\n"; \
_tt_out << "\ntime: " << duration_cast<duration<double>>(_tt_thetime).count() << "sec\n"; \
} \
else if (_tt_thetime >= std::chrono::milliseconds(1)) \
else \
_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: " \
_tt_out << "\ntime: " << duration_cast<duration<double,std::micro>>(_tt_thetime).count() << "us\n"; \
<< (double)(_tt_end-_tt_start)/(double)_tt_ticks << "sec\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)
#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_
#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