mirror of
https://github.com/jkriege2/JKQtPlotter.git
synced 2024-12-25 10:01:38 +08:00
JKQTPHighResTimer now uses C++11 chrono lib as fallback
This commit is contained in:
parent
9a667b9c22
commit
10965843da
@ -43,7 +43,7 @@ void JKQTPHighResTimer::start(){
|
||||
freq=static_cast<double>(fr.QuadPart);
|
||||
QueryPerformanceCounter(&last);
|
||||
#else
|
||||
gettimeofday(&last,0);
|
||||
last=std::chrono::system_clock::now();
|
||||
#endif
|
||||
};
|
||||
|
||||
@ -55,13 +55,8 @@ double JKQTPHighResTimer::getTime(){
|
||||
QueryPerformanceCounter(&now);
|
||||
return (static_cast<double>(now.QuadPart-last.QuadPart)/freq)*1e6;
|
||||
#else
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv,0);
|
||||
|
||||
int t1, t2;
|
||||
t1 = last.tv_sec * 1000000 + last.tv_usec;
|
||||
t2 = tv.tv_sec * 1000000 + tv.tv_usec;
|
||||
return abs(t2 - t1);
|
||||
auto no=std::chrono::system_clock::now();
|
||||
return std::chrono::duration_cast<std::chrono::microseconds>(no-last).count();
|
||||
|
||||
|
||||
#endif
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include <cmath>
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
#include <chrono>
|
||||
|
||||
#include "jkqtcommon_imexport.h"
|
||||
|
||||
@ -37,18 +38,11 @@
|
||||
# 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__)
|
||||
#include<windows.h>
|
||||
#elif defined(__LINUX__)
|
||||
#include <sys/time.h>
|
||||
#else
|
||||
#warning("your operating system is not supported: you will have to implement this on your systems")
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
|
||||
@ -133,7 +127,7 @@ class JKQTCOMMON_LIB_EXPORT JKQTPHighResTimer {
|
||||
/** \brief internal: time stamp of the last call of start() */
|
||||
LARGE_INTEGER last;
|
||||
#else
|
||||
struct timeval last;
|
||||
std::chrono::system_clock::timepoint last;
|
||||
#endif
|
||||
/** \brief internal: timer frequency */
|
||||
double freq;
|
||||
|
Loading…
Reference in New Issue
Block a user