In my software I collect some data and i need to attach to the data a time (in us). I tried to use
std::chrono::high_resolution_clock::now()
but it seems to have ~500uS of resolution
#include <chrono>
#include <iostream>
int _tmain(int argc, _TCHAR* argv[])
{
using namespace std::chrono;
int step = 0;
while (step < 100){
static int cnt = 1;
static high_resolution_clock::time_point t1 = high_resolution_clock::now();
high_resolution_clock::time_point t2 = high_resolution_clock::now();
if (t1 != t2) {
if (step++) std::cout << cnt << std::endl;
cnt = 1;
long long microseconds = duration_cast<std::chrono::microseconds>(t2 - t1).count();
std::cout << microseconds << " x";
t1 = t2;
}
else
cnt++;
}
std::cin.ignore();
return 0;
}
Results shows that t2 changes only if there is at least 500us between the previous call:
502 x1
1003 x1
1007 x1
1001 x1
999 x1
517 x1031
485 x1286
514 x909
487 x1008
499 x931
501 x1515
502 x1382
500 x1138
501 x437
501 x1
512 x95
491 x1
499 x139
502 x591
506 x694
496 x856
501 x1474
500 x1431
501 x1649
501 x1435
501 x1653
501 x1433
501 x769
501 x1442
501 x1067
501 x1
5520 x1
996 x1
1003 x1
501 x1
1001 x1
502 x1
1001 x1
Is there a better way to increase the precision?
Thanks