Stopwatch函數,猜測可能是用來計算一個函數的運行所需時間的.代碼如下:
Stopwatch wat = new Stopwatch();
wat.Start();
for (int i = 1; i < 100000; i++)
{
res1 = str.isNumberic1();
}
wat.Stop();
Console.WriteLine("isDigit {0}:{1},{2}", str, wat.ElapsedMilliseconds, res1);
wat.Reset();
wat.Start();
for (int i = 1; i < 100000; i++)
{
res2= str.isNumberic2();
}
wat.Stop();
Console.WriteLine("isNumberic {0}:{1},{2}", str, wat.ElapsedMilliseconds, res2);
wat.ElapsedMilliseconds返回值就是在wat.Start()和wat.Stop()之間函數運行的時間