38 #include <visp3/core/vpDebug.h>
39 #include <visp3/core/vpTime.h>
42 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11) && \
43 (defined(_MSC_VER) && _MSC_VER >= 1900 || !defined(_MSC_VER))
44 #define USE_CXX11_CHRONO 1
46 #define USE_CXX11_CHRONO 0
56 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
64 #ifndef DOXYGEN_SHOULD_SKIP_THIS
76 static const double minTimeForUsleepCall = 4;
93 std::chrono::system_clock::time_point now = std::chrono::system_clock::now();
94 return std::chrono::duration<double, std::micro>(now.time_since_epoch()).count();
98 LARGE_INTEGER time, frequency;
99 QueryPerformanceFrequency(&frequency);
100 if (frequency.QuadPart == 0) {
101 return (timeGetTime());
104 QueryPerformanceCounter(&time);
105 return (
double)(1000000.0 * time.QuadPart / frequency.QuadPart);
110 #elif !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
112 gettimeofday(&tp, 0);
113 return (1000000.0 * tp.tv_sec + tp.tv_usec);
127 std::chrono::system_clock::time_point now = std::chrono::system_clock::now();
128 return std::chrono::duration<double, std::milli>(now.time_since_epoch()).count();
132 LARGE_INTEGER time, frequency;
133 QueryPerformanceFrequency(&frequency);
134 if (frequency.QuadPart == 0) {
135 return (timeGetTime());
138 QueryPerformanceCounter(&time);
139 return (
double)(1000.0 * time.QuadPart / frequency.QuadPart);
144 #elif !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
146 gettimeofday(&tp, 0);
147 return (1000.0 * tp.tv_sec + tp.tv_usec / 1000.0);
172 int wait(
double t0,
double t)
174 double timeCurrent, timeToWait;
177 timeToWait = t0 + (t - timeCurrent);
179 if (timeToWait <= 0.) {
183 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
184 if (timeToWait > vpTime::minTimeForUsleepCall) {
185 usleep(
static_cast<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.) {
232 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
234 if (timeToWait > vpTime::minTimeForUsleepCall) {
235 usleep(
static_cast<useconds_t
>((timeToWait - vpTime::minTimeForUsleepCall) * 1000));
240 timeToWait = t0 + (t - timeCurrent);
242 }
while (timeToWait > 0.);
245 #elif defined(_WIN32)
246 #if !defined(WINRT_8_0)
248 if (timeToWait > vpTime::minTimeForUsleepCall) {
249 Sleep((DWORD)(timeToWait - vpTime::minTimeForUsleepCall));
254 timeToWait = t0 + t - timeCurrent;
256 }
while (timeToWait > 0.);
261 "vpTime::wait() is not implemented on Windows Phone 8.0"));
274 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
275 usleep(
static_cast<useconds_t
>(t * 1000));
276 #elif defined(_WIN32)
277 #if !defined(WINRT_8_0)
281 "vpTime::sleepMs() is not implemented on Windows Phone 8.0"));
366 timeinfo = localtime(&rawtime);
368 strftime(buffer, 80, format.c_str(), timeinfo);
369 std::string str(buffer);
374 #ifndef DOXYGEN_SHOULD_SKIP_THIS
402 m_lastTimePoint = std::chrono::steady_clock::now();
417 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()