42 #include <visp3/core/vpTime.h>
45 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11) && \
46 (defined(_MSC_VER) && _MSC_VER >= 1900 || !defined(_MSC_VER))
47 #define USE_CXX11_CHRONO 1
49 #define USE_CXX11_CHRONO 0
54 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
63 #ifndef DOXYGEN_SHOULD_SKIP_THIS
75 static const double minTimeForUsleepCall = 4;
92 std::chrono::system_clock::time_point now = std::chrono::system_clock::now();
93 return std::chrono::duration<double, std::micro>(now.time_since_epoch()).count();
97 LARGE_INTEGER time, frequency;
98 QueryPerformanceFrequency(&frequency);
99 if (frequency.QuadPart == 0) {
100 return (timeGetTime());
103 QueryPerformanceCounter(&time);
104 return (
double)(1000000.0 * time.QuadPart / frequency.QuadPart);
109 #elif !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
111 gettimeofday(&tp, 0);
112 return (1000000.0 * tp.tv_sec + tp.tv_usec);
126 std::chrono::system_clock::time_point now = std::chrono::system_clock::now();
127 return std::chrono::duration<double, std::milli>(now.time_since_epoch()).count();
131 LARGE_INTEGER time, frequency;
132 QueryPerformanceFrequency(&frequency);
133 if (frequency.QuadPart == 0) {
134 return (timeGetTime());
137 QueryPerformanceCounter(&time);
138 return (
double)(1000.0 * time.QuadPart / frequency.QuadPart);
143 #elif !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
145 gettimeofday(&tp, 0);
146 return (1000.0 * tp.tv_sec + tp.tv_usec / 1000.0);
171 int wait(
double t0,
double t)
173 double timeCurrent, timeToWait;
176 timeToWait = t0 + (t - timeCurrent);
178 if (timeToWait <= 0.) {
182 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
183 if (timeToWait > vpTime::minTimeForUsleepCall) {
184 usleep(
static_cast<useconds_t
>((timeToWait - vpTime::minTimeForUsleepCall) * 1000));
189 timeToWait = t0 + (t - timeCurrent);
191 }
while (timeToWait > 0.);
194 #elif defined(_WIN32)
195 #if !defined(WINRT_8_0)
196 if (timeToWait > vpTime::minTimeForUsleepCall) {
197 Sleep((DWORD)(timeToWait - vpTime::minTimeForUsleepCall));
202 timeToWait = t0 + t - timeCurrent;
204 }
while (timeToWait > 0.);
209 "vpTime::wait() is not implemented on Windows Phone 8.0"));
225 double timeToWait = t;
227 if (timeToWait <= 0.) {
231 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
233 if (timeToWait > vpTime::minTimeForUsleepCall) {
234 usleep(
static_cast<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__)))
274 usleep(
static_cast<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"));
368 timeinfo = localtime(&rawtime);
370 strftime(buffer, 80, format.c_str(), timeinfo);
371 std::string str(buffer);
376 #ifndef DOXYGEN_SHOULD_SKIP_THIS
404 m_lastTimePoint = std::chrono::steady_clock::now();
419 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()
error that can be emitted by ViSP classes.
@ functionNotImplementedError
Function not implemented.
Time management and measurement.
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")
VISP_EXPORT double measureTimeMs()