2012-10-19 3 views
4

나는 다음과 같은 코드가 있습니다 그렇게 큰 차이가 왜이 코드의부스트 :: 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 오류로 마이크로 초를 측정합니다 ???

답변

4

하여 Posix 시간 : microsec_clock :

는 서브 초 해상도 시계를 사용하여 UTC 시간을 가져옵니다. Unix 시스템에서 이것은 GetTimeOfDay를 사용하여 구현됩니다. 대부분의 Win32 플랫폼에서는 ftime을 사용하여 구현됩니다. Win32 시스템은 종종이 API를 통해 마이크로 초 해상도를 얻지 못합니다. 응용 프로그램에 더 높은 해상도가 중요한 경우 플랫폼을 테스트하여 달성 된 해상도를 확인하십시오.

ftime은 단순히 마이크로 초 해상도를 제공하지 않습니다. 인수에는 단어 microsecond이 포함될 수 있지만 구현시 해당 범위의 정확성을 제공하지 않습니다. 세분성은 ms 체제에 있습니다.

수술을 할 때 더 많은 시간이 필요하면 적어도 20ms 이상 차이가 날 것입니다.

편집 : 참고 : 긴GetSystemTimePreciseAsFileTime function 가능 사용해야 윈도우 microsec_clock 구현을 실행에 (.. 분 REQ 윈도우 8 바탕 화면, 윈도우 서버 2012 데스크탑) 마이크로 해상도를 달성하기 위해.

+0

이것은 단순히 boost :: posix_time :: microsec_clock이 거짓말임을 의미합니다. :) – Narek

+0

거짓말이라고 할 수는 없습니다. 값이 마이크로 초 범위의 정보를 전달하기 때문에 값에 마이크로 초가 있어야합니다. 그러나 세분성은 그 범위에 있지 않습니다. 일반적인 시나리오는 클럭 및 레벨이 156,250 100ns만큼 낮다는 것입니다. 이것은 15.625 ms, 즉 15 ms와 625 microseconds입니다. ** 그러나 시계는 그만큼 앞선다. 그것은 세세한 부분을 가지고 있습니다. ** – Arno

관련 문제