41#include <visp3/core/vpTime.h>
44#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11) && \
45 (defined(_MSC_VER) && _MSC_VER >= 1900 || !defined(_MSC_VER))
46#define USE_CXX11_CHRONO 1
48#define USE_CXX11_CHRONO 0
53#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
60# pragma clang diagnostic push
61# pragma clang diagnostic ignored "-Wnonportable-system-include-path"
67# pragma clang diagnostic pop
73#ifndef DOXYGEN_SHOULD_SKIP_THIS
85static const double minTimeForUsleepCall = 4;
102 std::chrono::system_clock::time_point now = std::chrono::system_clock::now();
103 return std::chrono::duration<double, std::micro>(now.time_since_epoch()).count();
107 LARGE_INTEGER time, frequency;
108 QueryPerformanceFrequency(&frequency);
109 if (frequency.QuadPart == 0) {
110 return (timeGetTime());
113 QueryPerformanceCounter(&time);
114 return static_cast<double>(1000000.0 * time.QuadPart / frequency.QuadPart);
119#elif !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
121 gettimeofday(&tp, 0);
122 return (1000000.0 * tp.tv_sec + tp.tv_usec);
136 std::chrono::system_clock::time_point now = std::chrono::system_clock::now();
137 return std::chrono::duration<double, std::milli>(now.time_since_epoch()).count();
141 LARGE_INTEGER time, frequency;
142 QueryPerformanceFrequency(&frequency);
143 if (frequency.QuadPart == 0) {
144 return (timeGetTime());
147 QueryPerformanceCounter(&time);
148 return static_cast<double>(1000.0 * time.QuadPart / frequency.QuadPart);
153#elif !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
155 gettimeofday(&tp, 0);
156 return (1000.0 * tp.tv_sec + tp.tv_usec / 1000.0);
181int wait(
double t0,
double t)
183 double timeCurrent, timeToWait;
186 timeToWait = t0 + (
t - timeCurrent);
188 if (timeToWait <= 0.) {
192#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
193 if (timeToWait > vpTime::minTimeForUsleepCall) {
194 usleep(
static_cast<useconds_t
>((timeToWait - vpTime::minTimeForUsleepCall) * 1000));
199 timeToWait = t0 + (
t - timeCurrent);
201 }
while (timeToWait > 0.);
205#if !defined(WINRT_8_0)
206 if (timeToWait > vpTime::minTimeForUsleepCall) {
207 Sleep(
static_cast<DWORD
>(timeToWait - vpTime::minTimeForUsleepCall));
212 timeToWait = t0 +
t - timeCurrent;
214 }
while (timeToWait > 0.);
219 "vpTime::wait() is not implemented on Windows Phone 8.0"));
235 double timeToWait =
t;
237 if (timeToWait <= 0.) {
241#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
243 if (timeToWait > vpTime::minTimeForUsleepCall) {
244 usleep(
static_cast<useconds_t
>((timeToWait - vpTime::minTimeForUsleepCall) * 1000));
249 timeToWait = t0 + (
t - timeCurrent);
251 }
while (timeToWait > 0.);
255#if !defined(WINRT_8_0)
257 if (timeToWait > vpTime::minTimeForUsleepCall) {
258 Sleep(
static_cast<DWORD
>(timeToWait - vpTime::minTimeForUsleepCall));
263 timeToWait = t0 +
t - timeCurrent;
265 }
while (timeToWait > 0.);
270 "vpTime::wait() is not implemented on Windows Phone 8.0"));
283#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
284 usleep(
static_cast<useconds_t
>(t * 1000));
286#if !defined(WINRT_8_0)
287 Sleep(
static_cast<DWORD
>(t));
290 "vpTime::sleepMs() is not implemented on Windows Phone 8.0"));
378 timeinfo = localtime(&rawtime);
380 strftime(buffer, 80,
format.c_str(), timeinfo);
381 std::string
str(buffer);
386#ifndef DOXYGEN_SHOULD_SKIP_THIS
414 m_lastTimePoint = std::chrono::steady_clock::now();
429 m_durationMs += std::chrono::duration<double, std::milli>(std::chrono::steady_clock::now() - m_lastTimePoint).count();
void start(bool reset=true)
double getDurationSeconds()
double getDurationMicros()
@ functionNotImplementedError
Function not implemented.
Time management and measurement.
VISP_EXPORT double measureTimeMs()
VISP_EXPORT int wait(double t0, double t)
VISP_EXPORT double measureTimeMicros()
VISP_EXPORT double getMinTimeForUsleepCall()
VISP_EXPORT double measureTimeSecond()
VISP_EXPORT void sleepMs(double t)
VISP_EXPORT std::string getDateTime(const std::string &format="%Y/%m/%d %H:%M:%S")