Я изучал различные методы цикла синхронизации времени, например. Гленн Фидлер и Де Виттер. Я обнаружил, что критические области трудно понять из-за моих собственных ограничений на знание C++. С этим я приступил к попытке реализовать свой собственный метод ... Я думал, что хороший способ попытаться понять что-то об этих методах.нечетное поведение с использованием chrono :: high_resolution_clock :: now()
[edit1: Я использую CodeBlocks IDE с MinGW-w64 (x64-4.8.1-POSIX-SEH-rev5) в качестве составителя]
[edit2: код и выходные окна с поправками включить 3-ю таймер, QueryPerformanceCounter]
в попытке достичь этого я наткнулся на следующий вопрос:
Минимальный код:
#include <chrono>
#include <iostream>
#include <windows.h>
#include <stdio.h>
using namespace std;
using namespace chrono;
LARGE_INTEGER startqpc, stopqpc, li;
double PCFreq = 0.0;
void print()
{
for (int p=0; p<1000000;) p += 1; //adjust till ms (steady) returns 1-2ms
}
int main()
{
for(int x=0; x<200; x += 1)
{
steady_clock::time_point start = steady_clock::now();
auto timePoint1 = chrono::high_resolution_clock::now();
if(!QueryPerformanceFrequency(&li))
cout << "QueryPerformanceFrequency failed!\n";
PCFreq = double(li.QuadPart)/1000.0;
QueryPerformanceCounter(&startqpc);
print();
steady_clock::time_point finish = steady_clock::now();
auto timePoint2 = chrono::high_resolution_clock::now();
QueryPerformanceCounter(&stopqpc);
auto elapsedTime(timePoint2 - timePoint1);
double diff = (stopqpc.QuadPart - startqpc.QuadPart)/PCFreq;
cout << "Elapsed time: "
<< duration_cast<milliseconds>(finish - start).count() << "ms (steady) "
<< chrono::duration_cast<chrono::duration<float, milli >> (elapsedTime).count() << "ms (hires) "
<< diff << " (qpc) \n";
}
}
для сравнения, выше трески e использует два таймера.
На моем компьютере выход из этого заключается в следующем:
Elapsed time: 1ms (steady) 0ms (hires) 1.8429 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.84209 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.8429 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.84209 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.84209 (qpc)
Elapsed time: 1ms (steady) 15.6ms (hires) 1.85152 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.84209 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.84209 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.84236 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.84209 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.84236 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.84209 (qpc)
Elapsed time: 1ms (steady) 15.6001ms (hires) 1.85557 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.84236 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.84209 (qpc)
Elapsed time: 2ms (steady) 0ms (hires) 2.59283 (qpc)
Elapsed time: 2ms (steady) 0ms (hires) 2.25573 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.84209 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.84236 (qpc)
Elapsed time: 1ms (steady) 15.6ms (hires) 1.85072 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.84236 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.84236 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.84263 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.84209 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.84263 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.84209 (qpc)
Elapsed time: 1ms (steady) 15.6ms (hires) 1.85422 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.84209 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.84209 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.84236 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.84263 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.84236 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.84263 (qpc)
Elapsed time: 1ms (steady) 15.6001ms (hires) 1.85099 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.84209 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.84209 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.84209 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.84236 (qpc)
Elapsed time: 2ms (steady) 0ms (hires) 2.31582 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.84236 (qpc)
Elapsed time: 1ms (steady) 15.6ms (hires) 1.84964 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.84236 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.84209 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.84209 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.84209 (qpc)
Elapsed time: 2ms (steady) 0ms (hires) 2.52466 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.84236 (qpc)
Elapsed time: 2ms (steady) 15.6ms (hires) 2.25169 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.84263 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.84209 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.84236 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.84209 (qpc)
Elapsed time: 2ms (steady) 0ms (hires) 2.26974 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.84209 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.84991 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.84667 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.84209 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.84236 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.84209 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.84209 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.89518 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.84236 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.87874 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.92213 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.87605 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.84236 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.84209 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.84263 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.84209 (qpc)
Elapsed time: 2ms (steady) 0ms (hires) 2.03126 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.84236 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.84236 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.84209 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.84236 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.87659 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.88467 (qpc)
Elapsed time: 2ms (steady) 0ms (hires) 2.24899 (qpc)
Elapsed time: 2ms (steady) 0ms (hires) 2.30316 (qpc)
Elapsed time: 2ms (steady) 0ms (hires) 2.23579 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.93263 (qpc)
Elapsed time: 2ms (steady) 0ms (hires) 2.23552 (qpc)
Elapsed time: 2ms (steady) 15.6ms (hires) 2.42118 (qpc)
Elapsed time: 2ms (steady) 0ms (hires) 2.24522 (qpc)
Elapsed time: 2ms (steady) 0ms (hires) 2.23471 (qpc)
Elapsed time: 2ms (steady) 0ms (hires) 2.23848 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.93425 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.9329 (qpc)
Elapsed time: 1ms (steady) 15.6001ms (hires) 1.85126 (qpc)
Elapsed time: 2ms (steady) 0ms (hires) 2.35355 (qpc)
Elapsed time: 2ms (steady) 0ms (hires) 2.23687 (qpc)
Elapsed time: 2ms (steady) 0ms (hires) 2.23633 (qpc)
Elapsed time: 2ms (steady) 0ms (hires) 2.2374 (qpc)
Elapsed time: 2ms (steady) 0ms (hires) 2.23498 (qpc)
Elapsed time: 1ms (steady) 15.6ms (hires) 1.85449 (qpc)
Elapsed time: 2ms (steady) 0ms (hires) 2.0097 (qpc)
Elapsed time: 2ms (steady) 0ms (hires) 2.15441 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.93263 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.93452 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.93425 (qpc)
Elapsed time: 2ms (steady) 0ms (hires) 2.23579 (qpc)
Elapsed time: 2ms (steady) 15.6ms (hires) 2.04554 (qpc)
Elapsed time: 2ms (steady) 0ms (hires) 2.1121 (qpc)
Elapsed time: 2ms (steady) 0ms (hires) 2.01779 (qpc)
Elapsed time: 2ms (steady) 0ms (hires) 2.07222 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.9329 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.93425 (qpc)
Elapsed time: 1ms (steady) 15.6001ms (hires) 1.95015 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.95177 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.84587 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.84452 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.84479 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.84425 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.84533 (qpc)
Elapsed time: 1ms (steady) 15.6ms (hires) 1.85233 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.88278 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.84667 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.84452 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.84452 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.84479 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.84533 (qpc)
Elapsed time: 1ms (steady) 15.6ms (hires) 1.88629 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.84506 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.84452 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.84452 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.84452 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.84452 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.8456 (qpc)
Elapsed time: 1ms (steady) 15.6ms (hires) 1.8588 (qpc)
Elapsed time: 2ms (steady) 0ms (hires) 2.06225 (qpc)
Elapsed time: 2ms (steady) 0ms (hires) 2.23633 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.93317 (qpc)
Elapsed time: 2ms (steady) 0ms (hires) 2.06009 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.84452 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.84533 (qpc)
Elapsed time: 1ms (steady) 15.6001ms (hires) 1.86284 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.84452 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.84452 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.93425 (qpc)
Elapsed time: 2ms (steady) 0ms (hires) 2.02803 (qpc)
Elapsed time: 2ms (steady) 0ms (hires) 2.26839 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.93398 (qpc)
Elapsed time: 1ms (steady) 15.6ms (hires) 1.93641 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.93371 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.93344 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.9329 (qpc)
Elapsed time: 2ms (steady) 0ms (hires) 2.02345 (qpc)
Elapsed time: 2ms (steady) 0ms (hires) 2.08731 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.9356 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.84506 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.93398 (qpc)
Elapsed time: 2ms (steady) 0ms (hires) 2.09 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.93371 (qpc)
Elapsed time: 2ms (steady) 0ms (hires) 2.03072 (qpc)
Elapsed time: 2ms (steady) 0ms (hires) 2.19213 (qpc)
Elapsed time: 1ms (steady) 15.6ms (hires) 1.85287 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.9321 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.93344 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.93317 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.93344 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.93263 (qpc)
Elapsed time: 2ms (steady) 0ms (hires) 2.42711 (qpc)
Elapsed time: 1ms (steady) 15.6001ms (hires) 1.9418 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.9356 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.84452 (qpc)
Elapsed time: 2ms (steady) 0ms (hires) 2.08947 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.9329 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.93614 (qpc)
Elapsed time: 2ms (steady) 15.6ms (hires) 2.27702 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.84452 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.93614 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.93317 (qpc)
Elapsed time: 2ms (steady) 0ms (hires) 2.08974 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.92698 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.93317 (qpc)
Elapsed time: 2ms (steady) 15.6ms (hires) 2.09054 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.96066 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.96093 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.8456 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.8456 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.8456 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.84533 (qpc)
Elapsed time: 1ms (steady) 15.6001ms (hires) 1.91835 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.8456 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.84587 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.8456 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.84452 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.84452 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.84452 (qpc)
Elapsed time: 1ms (steady) 15.6ms (hires) 1.85233 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.84425 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.84479 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.84452 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.93317 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.93317 (qpc)
Elapsed time: 2ms (steady) 0ms (hires) 2.23552 (qpc)
Elapsed time: 1ms (steady) 15.6ms (hires) 1.93102 (qpc)
Elapsed time: 2ms (steady) 0ms (hires) 2.07033 (qpc)
Elapsed time: 2ms (steady) 0ms (hires) 2.09405 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.9329 (qpc)
Elapsed time: 1ms (steady) 0ms (hires) 1.93263 (qpc)
Process returned 0 (0x0) execution time : 0.484 s
Press any key to continue.
Использование duration_cast<microseconds>(finish - start).count()/1000.0
для steady_clock мы видим следующее: -
Elapsed time: 1.842ms (steady) 0ms (hires) 1.84236 (qpc)
Elapsed time: 1.842ms (steady) 0ms (hires) 1.84263 (qpc)
Elapsed time: 1.843ms (steady) 0ms (hires) 1.84317 (qpc)
Elapsed time: 1.842ms (steady) 0ms (hires) 1.84236 (qpc)
Elapsed time: 1.846ms (steady) 0ms (hires) 1.84694 (qpc)
Elapsed time: 1.845ms (steady) 0ms (hires) 1.8456 (qpc)
Elapsed time: 1.877ms (steady) 0ms (hires) 1.87685 (qpc)
Elapsed time: 1.916ms (steady) 15.6ms (hires) 1.9162 (qpc)
Elapsed time: 1.906ms (steady) 0ms (hires) 1.90623 (qpc)
Elapsed time: 1.905ms (steady) 0ms (hires) 1.90515 (qpc)
Elapsed time: 1.909ms (steady) 0ms (hires) 1.90919 (qpc)
Elapsed time: 1.905ms (steady) 0ms (hires) 1.90542 (qpc)
Elapsed time: 1.905ms (steady) 0ms (hires) 1.90488 (qpc)
Elapsed time: 1.844ms (steady) 0ms (hires) 1.84452 (qpc)
Elapsed time: 1.943ms (steady) 15.6ms (hires) 1.94287 (qpc)
Elapsed time: 1.872ms (steady) 0ms (hires) 1.87281 (qpc)
Elapsed time: 1.842ms (steady) 0ms (hires) 1.84209 (qpc)
Elapsed time: 1.842ms (steady) 0ms (hires) 1.84209 (qpc)
Elapsed time: 1.842ms (steady) 0ms (hires) 1.84209 (qpc)
Elapsed time: 1.842ms (steady) 0ms (hires) 1.84209 (qpc)
Elapsed time: 1.842ms (steady) 0ms (hires) 1.84209 (qpc)
Elapsed time: 1.846ms (steady) 15.6001ms (hires) 1.8464 (qpc)
Elapsed time: 1.875ms (steady) 0ms (hires) 1.87497 (qpc)
Elapsed time: 2.033ms (steady) 0ms (hires) 2.03449 (qpc)
Elapsed time: 1.922ms (steady) 0ms (hires) 1.92293 (qpc)
Elapsed time: 1.922ms (steady) 0ms (hires) 1.92293 (qpc)
Elapsed time: 1.926ms (steady) 0ms (hires) 1.92698 (qpc)
Elapsed time: 2.004ms (steady) 15.6ms (hires) 2.00485 (qpc)
Elapsed time: 1.847ms (steady) 0ms (hires) 1.84748 (qpc)
Elapsed time: 1.847ms (steady) 0ms (hires) 1.84748 (qpc)
Elapsed time: 1.848ms (steady) 0ms (hires) 1.84856 (qpc)
Elapsed time: 1.849ms (steady) 0ms (hires) 1.84937 (qpc)
Elapsed time: 2.299ms (steady) 0ms (hires) 2.29938 (qpc)
Elapsed time: 3.497ms (steady) 15.6ms (hires) 3.49664 (qpc)
Elapsed time: 3.528ms (steady) 0ms (hires) 3.52843 (qpc)
Elapsed time: 2.299ms (steady) 0ms (hires) 2.29857 (qpc)
Elapsed time: 1.849ms (steady) 0ms (hires) 1.84937 (qpc)
Elapsed time: 1.848ms (steady) 0ms (hires) 1.84856 (qpc)
Elapsed time: 1.848ms (steady) 0ms (hires) 1.84856 (qpc)
Elapsed time: 1.842ms (steady) 0ms (hires) 1.84236 (qpc)
Elapsed time: 1.842ms (steady) 0ms (hires) 1.84263 (qpc)
Elapsed time: 1.842ms (steady) 0ms (hires) 1.84263 (qpc)
Elapsed time: 1.854ms (steady) 0ms (hires) 1.85395 (qpc)
Elapsed time: 1.842ms (steady) 0ms (hires) 1.84236 (qpc)
Elapsed time: 1.842ms (steady) 0ms (hires) 1.84236 (qpc)
Elapsed time: 1.842ms (steady) 0ms (hires) 1.84236 (qpc)
Elapsed time: 1.843ms (steady) 0ms (hires) 1.84371 (qpc)
Elapsed time: 1.842ms (steady) 0ms (hires) 1.8429 (qpc)
Elapsed time: 1.842ms (steady) 0ms (hires) 1.84236 (qpc)
Elapsed time: 1.842ms (steady) 0ms (hires) 1.84236 (qpc)
Elapsed time: 1.843ms (steady) 0ms (hires) 1.8429 (qpc)
Elapsed time: 1.842ms (steady) 0ms (hires) 1.84236 (qpc)
Elapsed time: 1.842ms (steady) 0ms (hires) 1.84236 (qpc)
Elapsed time: 1.861ms (steady) 0ms (hires) 1.86123 (qpc)
Elapsed time: 1.842ms (steady) 0ms (hires) 1.84236 (qpc)
Elapsed time: 1.842ms (steady) 0ms (hires) 1.84236 (qpc)
Elapsed time: 1.842ms (steady) 0ms (hires) 1.84209 (qpc)
Elapsed time: 1.842ms (steady) 0ms (hires) 1.84236 (qpc)
Elapsed time: 2.058ms (steady) 0ms (hires) 2.05848 (qpc)
Elapsed time: 1.842ms (steady) 0ms (hires) 1.84209 (qpc)
Elapsed time: 1.881ms (steady) 0ms (hires) 1.88144 (qpc)
Elapsed time: 1.842ms (steady) 0ms (hires) 1.84236 (qpc)
Elapsed time: 1.842ms (steady) 0ms (hires) 1.84209 (qpc)
Elapsed time: 1.842ms (steady) 0ms (hires) 1.84236 (qpc)
Elapsed time: 1.842ms (steady) 0ms (hires) 1.84209 (qpc)
Elapsed time: 1.845ms (steady) 0ms (hires) 1.84479 (qpc)
Elapsed time: 1.843ms (steady) 0ms (hires) 1.84371 (qpc)
Elapsed time: 1.842ms (steady) 0ms (hires) 1.84209 (qpc)
Elapsed time: 1.842ms (steady) 0ms (hires) 1.84209 (qpc)
Elapsed time: 1.842ms (steady) 0ms (hires) 1.84236 (qpc)
Elapsed time: 1.842ms (steady) 0ms (hires) 1.84209 (qpc)
Elapsed time: 1.842ms (steady) 0ms (hires) 1.84209 (qpc)
Elapsed time: 1.842ms (steady) 0ms (hires) 1.84209 (qpc)
Elapsed time: 1.896ms (steady) 0ms (hires) 1.89653 (qpc)
Elapsed time: 1.842ms (steady) 0ms (hires) 1.84236 (qpc)
Elapsed time: 1.843ms (steady) 0ms (hires) 1.84398 (qpc)
Elapsed time: 1.844ms (steady) 0ms (hires) 1.84452 (qpc)
Elapsed time: 1.844ms (steady) 0ms (hires) 1.84479 (qpc)
Elapsed time: 1.844ms (steady) 0ms (hires) 1.84452 (qpc)
Elapsed time: 1.844ms (steady) 0ms (hires) 1.84425 (qpc)
Elapsed time: 1.844ms (steady) 0ms (hires) 1.84452 (qpc)
Elapsed time: 1.886ms (steady) 0ms (hires) 1.88656 (qpc)
Elapsed time: 1.844ms (steady) 0ms (hires) 1.84452 (qpc)
Elapsed time: 1.845ms (steady) 0ms (hires) 1.84479 (qpc)
Elapsed time: 1.844ms (steady) 0ms (hires) 1.84452 (qpc)
Elapsed time: 1.844ms (steady) 0ms (hires) 1.84452 (qpc)
Elapsed time: 1.844ms (steady) 0ms (hires) 1.84479 (qpc)
Elapsed time: 1.85ms (steady) 15.6ms (hires) 1.85099 (qpc)
Elapsed time: 1.844ms (steady) 0ms (hires) 1.84452 (qpc)
Elapsed time: 1.844ms (steady) 0ms (hires) 1.84452 (qpc)
Elapsed time: 1.845ms (steady) 0ms (hires) 1.84506 (qpc)
Elapsed time: 1.845ms (steady) 0ms (hires) 1.84479 (qpc)
Elapsed time: 1.844ms (steady) 0ms (hires) 1.84452 (qpc)
Elapsed time: 1.844ms (steady) 0ms (hires) 1.84452 (qpc)
Elapsed time: 1.848ms (steady) 15.6001ms (hires) 1.84883 (qpc)
Elapsed time: 2.066ms (steady) 0ms (hires) 2.06683 (qpc)
Elapsed time: 1.845ms (steady) 0ms (hires) 1.84506 (qpc)
Elapsed time: 1.845ms (steady) 0ms (hires) 1.84506 (qpc)
Elapsed time: 1.845ms (steady) 0ms (hires) 1.84479 (qpc)
Elapsed time: 1.845ms (steady) 0ms (hires) 1.84506 (qpc)
Elapsed time: 1.845ms (steady) 0ms (hires) 1.84479 (qpc)
Elapsed time: 1.888ms (steady) 0ms (hires) 1.88817 (qpc)
Elapsed time: 1.844ms (steady) 0ms (hires) 1.84452 (qpc)
Elapsed time: 1.845ms (steady) 0ms (hires) 1.84479 (qpc)
Elapsed time: 1.844ms (steady) 0ms (hires) 1.84479 (qpc)
Elapsed time: 1.844ms (steady) 0ms (hires) 1.84506 (qpc)
Elapsed time: 1.844ms (steady) 0ms (hires) 1.84506 (qpc)
Elapsed time: 1.853ms (steady) 15.6ms (hires) 1.85341 (qpc)
Elapsed time: 1.844ms (steady) 0ms (hires) 1.84479 (qpc)
Elapsed time: 2.056ms (steady) 0ms (hires) 2.05605 (qpc)
Elapsed time: 1.88ms (steady) 0ms (hires) 1.8809 (qpc)
Elapsed time: 1.844ms (steady) 0ms (hires) 1.84479 (qpc)
Elapsed time: 1.845ms (steady) 0ms (hires) 1.84479 (qpc)
Elapsed time: 1.882ms (steady) 0ms (hires) 1.88224 (qpc)
Elapsed time: 1.849ms (steady) 15.6ms (hires) 1.85018 (qpc)
Elapsed time: 1.845ms (steady) 0ms (hires) 1.84479 (qpc)
Elapsed time: 1.844ms (steady) 0ms (hires) 1.84452 (qpc)
Elapsed time: 1.844ms (steady) 0ms (hires) 1.84479 (qpc)
Elapsed time: 1.845ms (steady) 0ms (hires) 1.84506 (qpc)
Elapsed time: 1.845ms (steady) 0ms (hires) 1.84506 (qpc)
Elapsed time: 1.844ms (steady) 0ms (hires) 1.84479 (qpc)
Elapsed time: 2.243ms (steady) 0ms (hires) 2.24333 (qpc)
Elapsed time: 1.844ms (steady) 0ms (hires) 1.84479 (qpc)
Elapsed time: 1.844ms (steady) 0ms (hires) 1.84452 (qpc)
Elapsed time: 1.845ms (steady) 0ms (hires) 1.84506 (qpc)
Elapsed time: 1.845ms (steady) 0ms (hires) 1.84506 (qpc)
Elapsed time: 1.844ms (steady) 0ms (hires) 1.84479 (qpc)
Elapsed time: 1.849ms (steady) 15.6ms (hires) 1.85018 (qpc)
Elapsed time: 1.845ms (steady) 0ms (hires) 1.84506 (qpc)
Elapsed time: 1.845ms (steady) 0ms (hires) 1.84506 (qpc)
Elapsed time: 2.109ms (steady) 0ms (hires) 2.10914 (qpc)
Elapsed time: 1.845ms (steady) 0ms (hires) 1.84533 (qpc)
Elapsed time: 1.845ms (steady) 0ms (hires) 1.84506 (qpc)
Elapsed time: 1.845ms (steady) 0ms (hires) 1.84506 (qpc)
Elapsed time: 1.845ms (steady) 0ms (hires) 1.84506 (qpc)
Elapsed time: 1.844ms (steady) 0ms (hires) 1.84479 (qpc)
Elapsed time: 1.845ms (steady) 0ms (hires) 1.84506 (qpc)
Elapsed time: 2.006ms (steady) 0ms (hires) 2.00647 (qpc)
Elapsed time: 1.844ms (steady) 0ms (hires) 1.84452 (qpc)
Elapsed time: 1.845ms (steady) 0ms (hires) 1.84506 (qpc)
Elapsed time: 1.852ms (steady) 15.6ms (hires) 1.8526 (qpc)
Elapsed time: 2.534ms (steady) 0ms (hires) 2.53463 (qpc)
Elapsed time: 2.368ms (steady) 0ms (hires) 2.3681 (qpc)
Elapsed time: 1.845ms (steady) 0ms (hires) 1.84533 (qpc)
Elapsed time: 1.844ms (steady) 0ms (hires) 1.84452 (qpc)
Elapsed time: 1.845ms (steady) 0ms (hires) 1.84479 (qpc)
Elapsed time: 1.845ms (steady) 0ms (hires) 1.84533 (qpc)
Elapsed time: 1.845ms (steady) 0ms (hires) 1.84506 (qpc)
Elapsed time: 1.845ms (steady) 0ms (hires) 1.84479 (qpc)
Elapsed time: 1.845ms (steady) 0ms (hires) 1.84479 (qpc)
Elapsed time: 1.845ms (steady) 0ms (hires) 1.84506 (qpc)
Elapsed time: 1.844ms (steady) 0ms (hires) 1.84479 (qpc)
Elapsed time: 1.844ms (steady) 0ms (hires) 1.84452 (qpc)
Elapsed time: 1.853ms (steady) 15.6ms (hires) 1.85368 (qpc)
Elapsed time: 1.843ms (steady) 0ms (hires) 1.84371 (qpc)
Elapsed time: 1.845ms (steady) 0ms (hires) 1.84533 (qpc)
Elapsed time: 1.844ms (steady) 0ms (hires) 1.84425 (qpc)
Elapsed time: 1.845ms (steady) 0ms (hires) 1.84479 (qpc)
Elapsed time: 1.844ms (steady) 0ms (hires) 1.84479 (qpc)
Elapsed time: 1.844ms (steady) 0ms (hires) 1.84506 (qpc)
Elapsed time: 1.852ms (steady) 15.6ms (hires) 1.85233 (qpc)
Elapsed time: 1.849ms (steady) 0ms (hires) 1.8491 (qpc)
Elapsed time: 1.845ms (steady) 0ms (hires) 1.84587 (qpc)
Elapsed time: 1.844ms (steady) 0ms (hires) 1.84425 (qpc)
Elapsed time: 1.844ms (steady) 0ms (hires) 1.84425 (qpc)
Elapsed time: 1.845ms (steady) 0ms (hires) 1.84479 (qpc)
Elapsed time: 1.844ms (steady) 0ms (hires) 1.84452 (qpc)
Elapsed time: 1.891ms (steady) 15.6001ms (hires) 1.89168 (qpc)
Elapsed time: 1.845ms (steady) 0ms (hires) 1.84506 (qpc)
Elapsed time: 1.846ms (steady) 0ms (hires) 1.84587 (qpc)
Elapsed time: 1.844ms (steady) 0ms (hires) 1.84425 (qpc)
Elapsed time: 1.844ms (steady) 0ms (hires) 1.84506 (qpc)
Elapsed time: 1.845ms (steady) 0ms (hires) 1.84479 (qpc)
Elapsed time: 1.845ms (steady) 0ms (hires) 1.84479 (qpc)
Elapsed time: 1.846ms (steady) 15.6ms (hires) 1.8464 (qpc)
Elapsed time: 1.845ms (steady) 0ms (hires) 1.84479 (qpc)
Elapsed time: 1.845ms (steady) 0ms (hires) 1.84587 (qpc)
Elapsed time: 1.844ms (steady) 0ms (hires) 1.84452 (qpc)
Elapsed time: 1.845ms (steady) 0ms (hires) 1.84479 (qpc)
Elapsed time: 1.845ms (steady) 0ms (hires) 1.84479 (qpc)
Elapsed time: 1.844ms (steady) 0ms (hires) 1.84479 (qpc)
Elapsed time: 1.848ms (steady) 15.6ms (hires) 1.84829 (qpc)
Elapsed time: 1.845ms (steady) 0ms (hires) 1.84506 (qpc)
Elapsed time: 1.845ms (steady) 0ms (hires) 1.8456 (qpc)
Elapsed time: 1.844ms (steady) 0ms (hires) 1.84425 (qpc)
Elapsed time: 1.844ms (steady) 0ms (hires) 1.84506 (qpc)
Elapsed time: 1.845ms (steady) 0ms (hires) 1.84479 (qpc)
Elapsed time: 1.845ms (steady) 0ms (hires) 1.84479 (qpc)
Elapsed time: 1.846ms (steady) 15.6ms (hires) 1.84614 (qpc)
Elapsed time: 1.844ms (steady) 0ms (hires) 1.84425 (qpc)
Elapsed time: 1.845ms (steady) 0ms (hires) 1.8456 (qpc)
Elapsed time: 1.844ms (steady) 0ms (hires) 1.84425 (qpc)
Elapsed time: 1.845ms (steady) 0ms (hires) 1.84479 (qpc)
Elapsed time: 1.845ms (steady) 0ms (hires) 1.84479 (qpc)
Elapsed time: 1.844ms (steady) 0ms (hires) 1.84506 (qpc)
Elapsed time: 1.872ms (steady) 15.6001ms (hires) 1.87281 (qpc)
Elapsed time: 1.844ms (steady) 0ms (hires) 1.84452 (qpc)
Elapsed time: 1.845ms (steady) 0ms (hires) 1.84587 (qpc)
Elapsed time: 1.844ms (steady) 0ms (hires) 1.84425 (qpc)
Elapsed time: 1.845ms (steady) 0ms (hires) 1.84479 (qpc)
Process returned 0 (0x0) execution time : 0.499 s
Press any key to continue
Обратите внимание, как высокое разрешение часы колеблется между 0 и 15,6 мс и обратите внимание на сравнение с установившимся временем.
Проблема заключается в том, что если бы я должен был реализовать цикл игры с фиксированным сроком, в котором код update() обновляет позиции объектов точно в 1000/60 (60 циклов обновления в секунду), то есть каждые 16.666etc мс - то это очень близко к возвращаемому таймеру, зависящему от количества часов! Реальная проблема заключается в том, что если я также реализую аккумулятор для того, чтобы учесть время цикла фрейма, равное 1000/60 мс, и любое оставшееся после завершения обновления(), цикл обновления вводится раньше - и в нерегулярные моменты времени - чем должно.
Есть ли проблема с минимальным кодом выше, а если нет, должен ли я быть заинтересован в этом для какой-либо надлежащей реализации фиксированного времени? Кроме того, и, если необходимо, есть ли способ изолировать программу/поток, чтобы он не прерывался системой IRQ или другими событиями опроса? Я предполагаю, что таймер найма может подвергаться таким перерывам.
Обычно вы используете сон, не занят, ждать –
я искусственно построил минимальный код, чтобы показать странное поведение, которое я испытываю с помощью таймера высокого разрешения. Мой фактический игровой код (не использует «ожидание») также демонстрирует эту проблему, когда игровые циклы колеблются от 0 до 15,6 мс ....... или более точно (где игровой цикл занят), там появляется проблема с 15.6 мс, нерегулярно добавленных в игровой цикл. – Jim
Я согласен с Беном Фойгтом в том, что реализация стандартной библиотеки std :: chrono в стандартной библиотеке багги. Даже при невысоком качестве реализации, я не вижу, насколько ваш результат разумный. Я не вижу ничего плохого в вашем коде. Возможно, на этой платформе вам нужно определить свои собственные 'chrono :: clock'. Вот пример того, как превратить инструкцию сборки rdtsc в 'chrono :: clock': http://stackoverflow.com/a/5524138/576911 –