我尝试实现.NET Stopwatch以获得乐趣,但我得到了一些意想不到的结果.
我完全期待这个程序的执行时间大约为100毫秒.
是Stopwatch类不准确或这到底是怎么回事呢?
码:
namespace Timer
{
class Program
{
Stopwatch s = new Stopwatch();
static void Main(string[] args)
{
s.Start();
for (int i = 0; i < 100; i++)
{
Thread.Sleep(1);
}
s.Stop();
Console.WriteLine("Elapsed Time " + s.ElapsedMilliseconds + " ms");
Console.ReadKey();
}
}
}
Run Code Online (Sandbox Code Playgroud)
结果是 190 ms
| 归档时间: |
|
| 查看次数: |
337 次 |
| 最近记录: |