나는 다음과 같은 코드가 있습니다 그렇게 큰 차이가 왜이 코드의부스트 :: posix_time :: microsec_clock 측정에 10 마이크로 초 이상 오류가 있습니까?
long long unsigned int GetCurrentTimestamp()
{
LARGE_INTEGER res;
QueryPerformanceCounter(&res);
return res.QuadPart;
}
long long unsigned int initalizeFrequency()
{
LARGE_INTEGER res;
QueryPerformanceFrequency(&res);
return res.QuadPart;
}
//start time stamp
boost::posix_time::ptime startTime = boost::posix_time::microsec_clock::local_time();
long long unsigned int start = GetCurrentTimestamp();
// ....
// execution that should be measured
// ....
long long unsigned int end = GetCurrentTimestamp();
boost::posix_time::ptime endTime = boost::posix_time::microsec_clock::local_time();
boost::posix_time::time_duration duration = endTime - startTime;
std::cout << "Duration by Boost posix: " << duration.total_microseconds() <<std::endl;
std::cout << "Processing time is " << ((end - start) * 1000000/initalizeFrequency())
<< " microsec "<< std::endl;
결과가
Duration by Boost posix: 0
Processing time is 24 microsec
입니까? 부스트는 마이크로 초를 측정해야하는만큼 빨기도하지만 마이크로 초의 10 분의 1 오류로 마이크로 초를 측정합니다 ???
이것은 단순히 boost :: posix_time :: microsec_clock이 거짓말임을 의미합니다. :) – Narek
거짓말이라고 할 수는 없습니다. 값이 마이크로 초 범위의 정보를 전달하기 때문에 값에 마이크로 초가 있어야합니다. 그러나 세분성은 그 범위에 있지 않습니다. 일반적인 시나리오는 클럭 및 레벨이 156,250 100ns만큼 낮다는 것입니다. 이것은 15.625 ms, 즉 15 ms와 625 microseconds입니다. ** 그러나 시계는 그만큼 앞선다. 그것은 세세한 부분을 가지고 있습니다. ** – Arno