作者xsoe (n/a)
看板java
标题Re: [问题] 时间上的问题
时间Tue Oct 3 17:51:44 2006
// 用C写个范例比较容易理解
// 如果用java写的话,结果会跟不精准的一样
// 除非有特殊方法...(这我就不了解了)
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
void main()
{
DWORD thisTick, lastTick;
LARGE_INTEGER thisClock, lastClock, Frequency;
QueryPerformanceFrequency( &Frequency );
lastTick = GetTickCount();
QueryPerformanceCounter( &lastClock );
for ( int i = 0; i < 10; i++ )
{
thisTick = GetTickCount();
QueryPerformanceCounter( &thisClock );
printf( "不精准时间差: %dms.\n", thisTick - lastTick );
printf( "精准的时间差: %0.2fms.\n",
(double)( thisClock.QuadPart - lastClock.QuadPart )
/ (double)( Frequency.QuadPart ) * 1000 );
printf( "\n" );
Sleep(1);
}
system( "PAUSE" );
}
/* 结果:
不精准时间差: 0ms.
精准的时间差: 0.00ms.
不精准时间差: 0ms.
精准的时间差: 1.95ms.
不精准时间差: 0ms.
精准的时间差: 3.88ms.
不精准时间差: 15ms.
精准的时间差: 5.87ms.
不精准时间差: 15ms.
精准的时间差: 7.79ms.
不精准时间差: 15ms.
精准的时间差: 9.74ms.
不精准时间差: 15ms.
精准的时间差: 11.71ms.
不精准时间差: 15ms.
精准的时间差: 13.65ms.
不精准时间差: 15ms.
精准的时间差: 15.60ms.
不精准时间差: 15ms.
精准的时间差: 17.55ms.
请按任意键继续 . . .
*/
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 210.60.29.254