//////////////////////////////////////////////////////////////////////////////// // test01.c - HRT and RDTSC tests for Windows OS. // // Note: Hrt - High Resolution Timer // Pcv - Performance Counter Value // Cc - Clock Cycles // Ns - Nano Seconds #include #include int main( void ) { BOOL bOK = FALSE; DWORD dwLastError = 0; double dHrtFrequency = 0.0L; LARGE_INTEGER liHrtFrequency = { 0, 0 }; LARGE_INTEGER liCc1 = { 0, 0 }; LARGE_INTEGER liCc2 = { 0, 0 }; unsigned __int64 uiCc1 = 0; unsigned __int64 uiCc2 = 0; double dValue1; double dValue2; size_t i; bOK = QueryPerformanceFrequency( &liHrtFrequency ); if( bOK == FALSE ) return ( int )0; dwLastError = GetLastError(); // Sub-Test1 { printf( "QueryPerformanceFrequency - Ticks Per Second: %ld Last Error: %d\n", liHrtFrequency.QuadPart, dwLastError ); dHrtFrequency = ( double )liHrtFrequency.QuadPart; printf( "QueryPerformanceFrequency - Ticks Per Second: %.0f Last Error: %d\n", dHrtFrequency, dwLastError ); printf( "\n" ); } // Sub-Test2 { printf( "QueryPerformanceCounter ( Pcv ) Rdtsc ( Cc )\n" ); for( i = 0; i < 300; i += 1 ) { uiCc1 = __rdtsc(); QueryPerformanceCounter( &liCc1 ); Sleep( 1000 ); uiCc2 = __rdtsc(); QueryPerformanceCounter( &liCc2 ); dValue1 = ( double )( liCc2.QuadPart - liCc1.QuadPart ) * 1000.0L; dValue2 = ( double )( uiCc2 - uiCc1 ); printf( "%.0f %.0f\n", dValue1, dValue2 ); } } return ( int )1; }