当前位置:编程学习 > C#/ASP.NET >>

Stopwatch的用法

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()之间函数运行的时间

    
补充:软件开发 , C# ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,