10#include <kernel/util/string.hpp>
12#include <kernel/util/os_windows.hpp>
18#if defined(__linux) || defined(__unix__)
19# define FEAT_HAVE_GETTIMEOFDAY 1
57#if defined(FEAT_HAVE_GETTIMEOFDAY)
60 long long int _counter;
81#if defined(FEAT_HAVE_GETTIMEOFDAY)
82 gettimeofday(&_time, 0);
102#if defined(FEAT_HAVE_GETTIMEOFDAY)
103 return double(_time.tv_sec - before._time.tv_sec) + 1E-6 * double(_time.tv_usec - before._time.tv_usec);
106 return (freq == 0ll) ? 0.0 : (double(_counter - before._counter) / double(freq));
108 return double(
_clock - before.
_clock) / double(CLOCKS_PER_SEC);
137#if defined(FEAT_HAVE_GETTIMEOFDAY)
138 return 1000000ll * (
long long)(_time.tv_sec - before._time.tv_sec)
139 + (
long long)(_time.tv_usec - before._time.tv_usec);
142 return (freq == 0ll) ? 0ll : (1000000ll * (_counter - before._counter)) / freq;
144 return 1000000ll * (
long long)(
_clock - before.
_clock) / (
long long)CLOCKS_PER_SEC;
159 return TimeStamp().elapsed_micros(*
this);
189 std::ostringstream oss;
190 oss << std::setfill(
'0');
202 oss << (micros / 3600000000ll);
203 oss <<
":" << std::setw(2) << ((micros / 60000000ll) % 60ll);
204 oss <<
":" << std::setw(2) << ((micros / 1000000ll) % 60ll);
205 oss <<
"." << std::setw(3) << ((micros / 1000ll) % 1000ll);
209 oss << (micros / 3600000000ll);
210 oss <<
":" << std::setw(2) << ((micros / 60000000ll) % 60ll);
211 oss <<
":" << std::setw(2) << ((micros / 1000000ll) % 60ll);
215 oss << (micros / 60000000ll);
216 oss <<
":" << std::setw(2) << ((micros / 1000000ll) % 60ll);
217 oss <<
"." << std::setw(3) << ((micros / 1000ll) % 1000ll);
221 oss << (micros / 60000000ll);
222 oss <<
":" << std::setw(2) << ((micros / 1000000ll) % 60ll);
226 oss << (micros / 1000000ll);
227 oss <<
"." << std::setw(3) << ((micros / 1000ll) % 1000ll);
231 XABORTM(
"TimeFormat not supported!");
275 return TimeStamp().elapsed_string(*
this, format);
289#if defined(FEAT_HAVE_GETTIMEOFDAY)
290 return (_time.tv_sec < other._time.tv_sec) ||
291 ((_time.tv_sec == other._time.tv_sec) && (_time.tv_usec < other._time.tv_usec));
293 return (_counter < other._counter);
295 return (
_clock < other._clock);
#define XABORTM(msg)
Abortion macro definition with custom message.
String class implementation.
static String format_micros(long long micros, TimeFormat format=TimeFormat::s_m)
Formats an elapsed time in microseconds as a string.
TimeStamp & stamp()
Stamps the current time-stamp.
String elapsed_string(const TimeStamp &before, TimeFormat format=TimeFormat::s_m) const
Return the time elapsed between two time stamps as a string.
clock_t _clock
Our time-stamp.
String elapsed_string_now(TimeFormat format=TimeFormat::s_m) const
Calculates the time elapsed between the time stamp and now as a string.
bool operator<(const TimeStamp &other) const
Comparison operator.
long long elapsed_micros(const TimeStamp &before) const
Calculate the time elapsed between two time stamps in microseconds.
double elapsed(const TimeStamp &before) const
Calculates the time elapsed between two time stamps.
double elapsed_now() const
Calculates the time elapsed between the time stamp and now.
long long elapsed_micros_now() const
Calculates the time elapsed between the time stamp and now in microseconds.
long long query_performance_frequency()
Wraps around the QueryPerformanceCounter function.
long long query_performance_counter()
Wraps around the QueryPerformanceCounter function.