我想测量我的代码的性能。如果我把时间作为一个标准,我有这样的代码
DateTime oldDate = new DateTime(2002,7,15);
DateTime newDate = DateTime.Now;
// Difference in days, hours, and minutes.
TimeSpan ts = newDate - oldDate;
// Difference in days.
int differenceInDays = ts.Milliseconds ;Question1:这是我测试算法性能的唯一方法吗?Question2: C#还提供了哪些其他标准来测试性能?问候
发布于 2011-02-15 13:56:54
使用System.Diagnostics.Stopwatch总是更好
有关更多详细信息,请查看此链接。Performance Tests: Precise Run Time Measurements with System.Diagnostics.Stopwatch
发布于 2011-02-15 13:58:55
使用Stopwatch类
//启动秒表:
var watch = Stopwatch.StartNew();//执行代码
watch.Stop(); //This stops the watch使用、ElapsedMilliSeconds和ElapsedTicks属性可以测量经过的时间。
发布于 2011-02-15 13:54:50
尝试使用StopWatch类。它比DateTime和TimeSpan类具有更高的分辨率。
此外,您可以将Windows Performance Counters视为在应用程序运行时测量性能的一种方法,以便监视应用程序的健康状况。
https://stackoverflow.com/questions/5000330
复制相似问题