42 #include <visp3/core/vpDebug.h> 43 #include <visp3/core/vpTime.h> 46 #if VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11 && (defined(_MSC_VER) && _MSC_VER >= 1900 || !defined(_MSC_VER)) 47 #define USE_CXX11_CHRONO 1 49 #define USE_CXX11_CHRONO 0 59 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX 67 #ifndef DOXYGEN_SHOULD_SKIP_THIS 79 static const double minTimeForUsleepCall = 4;
96 std::chrono::system_clock::time_point now = std::chrono::system_clock::now();
97 return std::chrono::duration<double, std::micro>(now.time_since_epoch()).count();
101 LARGE_INTEGER time, frequency;
102 QueryPerformanceFrequency(&frequency);
103 if (frequency.QuadPart == 0) {
104 return (timeGetTime());
106 QueryPerformanceCounter(&time);
107 return (
double)(1000000.0 * time.QuadPart / frequency.QuadPart);
112 #elif !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX 114 gettimeofday(&tp, 0);
115 return (1000000.0 * tp.tv_sec + tp.tv_usec);
129 std::chrono::system_clock::time_point now = std::chrono::system_clock::now();
130 return std::chrono::duration<double, std::milli>(now.time_since_epoch()).count();
134 LARGE_INTEGER time, frequency;
135 QueryPerformanceFrequency(&frequency);
136 if (frequency.QuadPart == 0) {
137 return (timeGetTime());
139 QueryPerformanceCounter(&time);
140 return (
double)(1000.0 * time.QuadPart / frequency.QuadPart);
145 #elif !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX 147 gettimeofday(&tp, 0);
148 return (1000.0 * tp.tv_sec + tp.tv_usec / 1000.0);
175 double timeCurrent, timeToWait;
178 timeToWait = t0 + t - timeCurrent;
180 if (timeToWait <= 0.)
183 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX 184 if (timeToWait > vpTime::minTimeForUsleepCall) {
185 usleep((useconds_t)((timeToWait - vpTime::minTimeForUsleepCall) * 1000));
190 timeToWait = t0 + t - timeCurrent;
192 }
while (timeToWait > 0.);
195 #elif defined(_WIN32) 196 #if !defined(WINRT_8_0) 197 if (timeToWait > vpTime::minTimeForUsleepCall) {
198 Sleep((DWORD)(timeToWait - vpTime::minTimeForUsleepCall));
203 timeToWait = t0 + t - timeCurrent;
205 }
while (timeToWait > 0.);
210 "vpTime::wait() is not implemented on Windows Phone 8.0"));
226 double timeToWait = t;
228 if (timeToWait <= 0.)
231 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX 233 if (timeToWait > vpTime::minTimeForUsleepCall) {
234 usleep((useconds_t)((timeToWait - vpTime::minTimeForUsleepCall) * 1000));
239 timeToWait = t0 + t - timeCurrent;
241 }
while (timeToWait > 0.);
244 #elif defined(_WIN32) 245 #if !defined(WINRT_8_0) 247 if (timeToWait > vpTime::minTimeForUsleepCall) {
248 Sleep((DWORD)(timeToWait - vpTime::minTimeForUsleepCall));
253 timeToWait = t0 + t - timeCurrent;
255 }
while (timeToWait > 0.);
260 "vpTime::wait() is not implemented on Windows Phone 8.0"));
273 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX 274 usleep((useconds_t)(t * 1000));
275 #elif defined(_WIN32) 276 #if !defined(WINRT_8_0) 280 "vpTime::sleepMs() is not implemented on Windows Phone 8.0"));
365 timeinfo = localtime(&rawtime);
367 strftime(buffer, 80, format.c_str(), timeinfo);
368 std::string str(buffer);
373 #ifndef DOXYGEN_SHOULD_SKIP_THIS 386 return m_durationMs * 1e3;
402 return m_durationMs * 1e-3;
412 m_lastTimePoint = std::chrono::steady_clock::now();
427 m_durationMs += std::chrono::duration<double, std::milli>(std::chrono::steady_clock::now() - m_lastTimePoint).count();
double getDurationMicros()
VISP_EXPORT int wait(double t0, double t)
Time management and measurement.
VISP_EXPORT double measureTimeSecond()
double getDurationSeconds()
error that can be emited by ViSP classes.
VISP_EXPORT double measureTimeMs()
VISP_EXPORT std::string getDateTime(const std::string &format="%Y/%m/%d %H:%M:%S")
void start(bool reset=true)
VISP_EXPORT void sleepMs(double t)
VISP_EXPORT double measureTimeMicros()
VISP_EXPORT double getMinTimeForUsleepCall()
Function not implemented.