作者cole945 (躂躂..)
看板C_Sharp
标题Re: [问题] 时间计算 问题
时间Tue Apr 1 19:20:46 2008
※ 引述《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