简体   繁体   English

在Windows中对程序进行基准测试的最佳方法是什么?

[英]What's the best way to benchmark programs in Windows?

I need to do some performance benchmarks on .NET programs (C#) in Windows, but I haven't done benchmarking much in the Windows world. 我需要在Windows中对.NET程序(C#)做一些性能基准测试,但我还没有在Windows世界中做过很多基准测试。 I've looked into using the Windows 2000/XP Performance monitor with custom counters for this, but I don't think this is quite what I want. 我已经研究过使用带有自定义计数器的Windows 2000 / XP性能监视器,但我认为这不是我想要的。

Are there any good system facilities for this in Windows XP, or do I need to just use System.Diagnostics.Stopwatch [edit] and write text logs for manual interpretation, or is there something else? 在Windows XP中是否有适用于此的良好系统设施,或者我是否需要使用System.Diagnostics.Stopwatch [编辑]并编写文本日志以进行手动解释,或者还有其他什么?

Edit: is there anything beyond System.Diagnostics.Stopwatch ? 编辑:除了System.Diagnostics.Stopwatch还有什么吗?

using System.Diagnostics;
....

Stopwatch sw = new Stopwatch();

sw.Start();

// Code you want to time...

// Note: for averaged accuracy (without other OS effects), 
//       run timed code multiple times in a loop 
//       and then divide by the number of runs.

sw.Stop();

Console.WriteLine("Took " + sw.ElapsedTicks + " Ticks");

For micro-benchmarking I really like MeasureIt (can be downloaded from http://msdn.microsoft.com/en-us/magazine/cc500596.aspx ). 对于微基准测试,我非常喜欢MeasureIt(可以从http://msdn.microsoft.com/en-us/magazine/cc500596.aspx下载)。 It is a test project written by Vance Morrison a Performance Architect on the CLR. 这是由CLR的性能架构师Vance Morrison编写的测试项目。 It currently has a good set of benchmarks for a number of .Net/CLR core methods. 它目前为许多.Net / CLR核心方法提供了一套很好的基准。 The best part of it is that it is trivial to tweak and add new benchmarks for whatever you would like to test. 最好的部分是,无论你想测试什么,调整和添加新基准都是微不足道的。 Simply run "MeasureIt /edit" and it will launch VS with the project for itself so that you can view how those benchmarks are written and add new ones in a similar fashion if you like. 只需运行“MeasureIt / edit”,它就会自动启动VS项目,以便您可以查看这些基准测试的编写方式,并以类似的方式添加新的基准测试。

As already been stated StopWatch is probably the easiest way to do this and MeasureIt uses StopWatch underneath for its timings but it also does some other things like running a block of code X times and then providing you stats for the runs and what not. 正如已经说明的那样,StopWatch可能是最简单的方法,而MeasureIt使用下面的StopWatch作为其时间,但它也做了一些其他的事情,比如运行一段代码X次,然后为运行提供统计数据,而不是。

There are quite a few profilers out there. 那里有很多个人。 Here are some of the ones I know of: 以下是我所知道的一些内容:

If you go on with using System.Diagnostics.Stopwatch, you will be able to instrument and measure only particular points of your code, where you explicitly put the Start/Stop around. 如果继续使用System.Diagnostics.Stopwatch,您将能够只测量和测量代码的特定点,您可以在其中明确地设置Start / Stop。 This is good enough for measuring specific pieces, like a tight loop or things like that, but it's not going to give you a complete picture of where your program spends most of its time. 这足以测量特定的部分,比如紧凑的循环或类似的东西,但它不会让你全面了解你的程序花费大部分时间的位置。

If you want just some quick numbers, you can use Powershell to time overall execution. 如果您只想要一些快速数字,可以使用Powershell来计算整体执行时间。 Use the measure-command cmdlet. 使用measure-command cmdlet。 It's roughly equivalent to "time" in Unix. 它大致相当于Unix中的“时间”。

> measure-command { your.exe arg1 }

Days              : 0
Hours             : 0
Minutes           : 0
Seconds           : 4
Milliseconds      : 996
Ticks             : 49963029
TotalDays         : 5.78275798611111E-05
TotalHours        : 0.00138786191666667
TotalMinutes      : 0.083271715
TotalSeconds      : 4.9963029
TotalMilliseconds : 4996.3029

这可能不是您想要的,但dotTrace提供了许多有用的诊断并集成到Visual Studio中。

如果您的项目非常庞大并且有很多模块在进行大量通话,您可以: http//www.moduleanalyzer.com/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 .NET Windows窗体应用程序更新自身的最佳方法是什么? - What's the best way for a .NET windows forms application to update itself? 在Windows和Web App中处理数据库升级的最佳方法是什么? - What's the best way to process database upgrades in Windows and Web App? 同一台机器上的两个程序相互通信的最佳方法是什么 - What is the best way for two programs on the same machine to communicate with each other 跨程序发送自定义ACS声明的最佳方法是什么? - What is the best way to send custom ACS Claims across programs? 什么是多线程的最佳方式? - What's the best way to multithread? 以编程方式启用Windows功能的最佳方法是什么? - What is the best way to enable Windows feature programmatically? 什么是在Windows窗体中进行验证的最佳方法 - What is the best way to do validations in windows forms 自动执行Windows服务部署的最佳方法是什么? - What is the best way of automating Windows Service deployment? 从Windows Universal应用程序将docx / pptx文档转换为PDF的最佳方法是什么? - What's the best way to convert docx/pptx documents to PDF from a Windows Universal App? 为ASP.NET MVC Intranet应用程序实施Windows身份验证的最佳方法是什么? - What's the best way to implement Windows Authentication for an ASP.NET MVC intranet application?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM