JKQTPHighResTimer now uses C++11 chrono lib as fallback

This commit is contained in:
jkriege2 2019-11-24 12:21:06 +01:00
parent 9a667b9c22
commit 10965843da
2 changed files with 5 additions and 16 deletions

View File

@ -43,7 +43,7 @@ void JKQTPHighResTimer::start(){
freq=static_cast<double>(fr.QuadPart); freq=static_cast<double>(fr.QuadPart);
QueryPerformanceCounter(&last); QueryPerformanceCounter(&last);
#else #else
gettimeofday(&last,0); last=std::chrono::system_clock::now();
#endif #endif
}; };
@ -55,13 +55,8 @@ double JKQTPHighResTimer::getTime(){
QueryPerformanceCounter(&now); QueryPerformanceCounter(&now);
return (static_cast<double>(now.QuadPart-last.QuadPart)/freq)*1e6; return (static_cast<double>(now.QuadPart-last.QuadPart)/freq)*1e6;
#else #else
struct timeval tv; auto no=std::chrono::system_clock::now();
gettimeofday(&tv,0); return std::chrono::duration_cast<std::chrono::microseconds>(no-last).count();
int t1, t2;
t1 = last.tv_sec * 1000000 + last.tv_usec;
t2 = tv.tv_sec * 1000000 + tv.tv_usec;
return abs(t2 - t1);
#endif #endif

View File

@ -22,6 +22,7 @@
#include <cmath> #include <cmath>
#include <cstdlib> #include <cstdlib>
#include <iostream> #include <iostream>
#include <chrono>
#include "jkqtcommon_imexport.h" #include "jkqtcommon_imexport.h"
@ -37,18 +38,11 @@
# endif # endif
#endif #endif
#ifndef __WINDOWS__
# ifndef __LINUX__
# warning("these methods are ment to be used under windows or linux ... no other system were tested")
# endif
#endif
#if defined(__WINDOWS__) #if defined(__WINDOWS__)
#include<windows.h> #include<windows.h>
#elif defined(__LINUX__) #elif defined(__LINUX__)
#include <sys/time.h> #include <sys/time.h>
#else #else
#warning("your operating system is not supported: you will have to implement this on your systems")
#include <sys/time.h> #include <sys/time.h>
#endif #endif
@ -133,7 +127,7 @@ class JKQTCOMMON_LIB_EXPORT JKQTPHighResTimer {
/** \brief internal: time stamp of the last call of start() */ /** \brief internal: time stamp of the last call of start() */
LARGE_INTEGER last; LARGE_INTEGER last;
#else #else
struct timeval last; std::chrono::system_clock::timepoint last;
#endif #endif
/** \brief internal: timer frequency */ /** \brief internal: timer frequency */
double freq; double freq;