如何监视方法执行速度 [英] How to monitor method execution speeds

查看:98
本文介绍了如何监视方法执行速度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我对正在开发的软件进行了一些细微的更改,现在它在其他计算机上的运行速度非常慢(由于具有强大的四核处理器,因此在我的计算机上可以快速运行).我尝试单步执行代码,但无法找出导致缓慢问题的原因.我什至回顾并简化了一些方法,但是在其他计算机上仍然没有任何改进.
当其他人使用该软件时,我观察到了该软件,并且给人的印象是,数据实际上加载得更快,但是其自身更新的形式却非常缓慢.无论如何,有什么原因可以跟踪导致软件运行缓慢的原因?

Hi,
I have made some slight changes to the software I''m developing and now it''s performing extremely slow on other computers (it works fast on my computer because it has a very powerful quad core processor). I tried stepping through the code but I can''t find out what''s causing the slow problem. I even reviewed and simplified some methods but still there''s no improvement on other computers.
I observed the software when other people use it and I got the impression that the data is actually loading faster but the form it self updates very slowly. Is there anyway to track what''s causing the software to run slow?

推荐答案

请查看我对CP上类似问题的回答:如何高速应用? [
Please have a look at my answer to a similar question here on CP: how high Speed Application?[^]. You want to use such a profiling tool in order to find out where the bottlenecks in your application are occurring.

Happy coding and profiling!

-MRB


首先,有一类名为 Profilers 的开发工具.好的Profiler可以在受控的情况下运行软件产品,并有助于非常迅速地发现性能瓶颈.开发人员使用此信息来改善性能关键代码的一小部分,然后在Profiler下再次运行它.

您可以尝试执行搜索以找到合适的Profiler.目前,我无法为好的.NET Profiler提供某些建议.

如果只需要偶尔测量代码片段的性能,则可以使用类System.Diagnostics.Stopwatch:
创建一个简单的家庭烘焙 ad "Profiler"
First, there is a class of development tools called Profilers. A good Profiler runs a software product under control and helps to find out performance bottlenecks very rapidly. The developer uses this information to improve performance of small fraction of performance critical code and runs it under the Profiler again.

You can try to perform your search to find appropriate Profiler. At this moment, I cannot give certain recommendations for a good .NET Profiler.

If you need to measure performance of the fragments of code only occasionally, you can create a simple home-baked ad-hoc "Profiler" using the class System.Diagnostics.Stopwatch:

System.Diagnostics.Stopwatch stopWatch = new System.Diagnostics.Stopwatch();

//..

stopWatch.Start();
//some code to time
stopWatch.Stop();

System.TimeSpan duration = stopWatch.Elapsed;

//don't use Millisecond which will be rounded to integer value;
//use TotalMilliseconds or TotalSeconds and the like:
double elapsedTimeMs = duration.TotalMilliseconds;



与计时器类或System.DateTime类相比,类Stopwatch具有更好的准确性;这是衡量性能的最佳课程.

—SA



The class Stopwatch has much better accuracy compared to timer classes or System.DateTime class; this is the best class to measure performance.

—SA


这篇关于如何监视方法执行速度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆