Blaze
3.9
Toggle main menu visibility
Loading...
Searching...
No Matches
blaze
util
Time.h
Go to the documentation of this file.
1
//=================================================================================================
33
//=================================================================================================
34
35
#ifndef _BLAZE_UTIL_TIME_H_
36
#define _BLAZE_UTIL_TIME_H_
37
38
39
//*************************************************************************************************
40
// Includes
41
//*************************************************************************************************
42
43
#if defined(_MSC_VER) || defined(__MINGW64_VERSION_MAJOR) || defined(__MINGW32__)
44
# ifndef NOMINMAX
45
# define NOMINMAX
46
# endif
47
# include <windows.h>
48
# include <winsock.h>
49
# include <time.h>
50
# include <sys/timeb.h>
51
#else
52
# include <sys/resource.h>
53
# include <sys/time.h>
54
# include <sys/types.h>
55
#endif
56
#include <ctime>
57
#include <string>
58
59
60
namespace
blaze {
61
62
//=================================================================================================
63
//
64
// TIME FUNCTIONS
65
//
66
//=================================================================================================
67
68
//*************************************************************************************************
71
inline
std::string
getDate
();
72
inline
std::string
getTime
();
73
inline
double
getWcTime
();
74
inline
double
getCpuTime
();
76
//*************************************************************************************************
77
78
79
//*************************************************************************************************
85
inline
std::string
getDate
()
86
{
87
std::time_t t;
88
std::tm* localTime;
89
char
c[50];
90
91
std::time( &t );
92
localTime = std::localtime( &t );
93
std::strftime( c, 50,
"%Y-%m-%d"
, localTime );
94
95
return
std::string( c );
96
}
97
//*************************************************************************************************
98
99
100
//*************************************************************************************************
106
inline
std::string
getTime
()
107
{
108
std::time_t t;
109
std::tm* localTime;
110
char
c[50];
111
112
std::time( &t );
113
localTime = std::localtime( &t );
114
std::strftime( c, 50,
"%A, %d.%B %Y, %H:%M"
, localTime );
115
116
return
std::string( c );
117
}
118
//*************************************************************************************************
119
120
121
//*************************************************************************************************
127
inline
double
getWcTime
()
128
{
129
#ifdef WIN32
130
struct
_timeb timeptr;
131
_ftime64_s( &timeptr );
132
return
(
static_cast<
double
>
( timeptr.time ) +
static_cast<
double
>
( timeptr.millitm )/1E3 );
133
#else
134
struct
timeval tp;
135
gettimeofday( &tp,
nullptr
);
136
return
(
static_cast<
double
>
( tp.tv_sec ) +
static_cast<
double
>
( tp.tv_usec )/1E6 );
137
#endif
138
}
139
//*************************************************************************************************
140
141
142
//*************************************************************************************************
148
inline
double
getCpuTime
()
149
{
150
#ifdef WIN32
151
FILETIME CreateTime, ExitTime, KernelTime, UserTime;
152
SYSTEMTIME SysTime;
153
154
if
( GetProcessTimes( GetCurrentProcess(), &CreateTime, &ExitTime, &KernelTime, &UserTime ) != TRUE ) {
155
return
0.0;
156
}
157
else
{
158
FileTimeToSystemTime( &UserTime, &SysTime );
159
return
(
static_cast<
double
>
( SysTime.wSecond ) +
static_cast<
double
>
( SysTime.wMilliseconds )/1E3 );
160
}
161
#else
162
struct
rusage ruse;
163
getrusage( RUSAGE_SELF, &ruse );
164
return
(
static_cast<
double
>
( ruse.ru_utime.tv_sec ) +
static_cast<
double
>
( ruse.ru_utime.tv_usec )/1E6 );
165
#endif
166
}
167
//*************************************************************************************************
168
169
}
// namespace blaze
170
171
#endif
blaze::getWcTime
double getWcTime()
Returns the current wall clock time in seconds.
Definition
Time.h:127
blaze::getCpuTime
double getCpuTime()
Returns the current CPU time in seconds.
Definition
Time.h:148
blaze::getTime
std::string getTime()
Creating a formated time and date string.
Definition
Time.h:106
blaze::getDate
std::string getDate()
Creating a formated date string in the form YYYY-MM-DD.
Definition
Time.h:85
Generated by
1.18.0