※ 引述《toki (いまがその時だ)》之銘言:
: 要測比秒還小的建議用 System.Environment.TickCount
: 此值等同於 Windows API 的 GetTickCount();
: 執行前後各取一次值然後相減,減出來的單位是 ms (1/1000) 秒
: 要再小的 Performance Counter 裡有 CPU tick,可以準到百萬分之一秒
GetTickCount() 沒有到 1/1000 秒 @.@"
在我的 Windows XP Pro/P4 上執行下面程式只會印出 15和16,
所以 GetTickCount 應該只會到 1/64 = 15.625 秒而已 @.@
這個好像是 OS 為了避免 因為不斷更新 timer 值對效能造成負面影響所致..
如果真的要很準, 用 Performance Counter (通常不會需要吧)
while (true) {
a = GetTickCount();
if (a != b) {
Console.WriteLine((a - b).ToString());
b = a;
}
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 220.139.138.126