有没有说每种方法需要花费多长时间的工具? [英] Any tool that says how long each method takes to run?
本文介绍了有没有说每种方法需要花费多长时间的工具?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的程序的某些部分运行缓慢.我想知道是否有我可以使用的工具,例如,它可以告诉我可以正常运行methodA()花费了100ms,等等……或类似的有用信息.
some parts of my program are way slow. and I was wondering if there is tool that i can use and for example it can tell me ok running methodA() took 100ms , etc ...or so useful info similar to that.
推荐答案
System.Diagnostics命名空间提供了一个有用的类,称为
The System.Diagnostics namespace offers a helpful class called Stopwatch, which can be used to time parts of your code (think of it as a "poor man's profiler").
这是您将如何使用它:
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start(); // Start timing
// This is what we want to time
DoSomethingWeSuspectIsSlow();
stopwatch.Stop();
Console.WriteLine("It took {0} ms.", stopwatch.ElapsedMilliseconds);
这篇关于有没有说每种方法需要花费多长时间的工具?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文