在Mono上监视你的程序性能的方法
Mono --profile 参数可以帮助我们监视应用程序的运行性能
很方便的一个功能使用也很简单:
Example: Mono --profile app.exe > app.txt生成的 app.txt 就是 app.exe 的运行记录。
文档中会有如下记录:
Total time spent compiling 1466 methods (sec): 0.3906 Slowest method to compile (sec): 0.0625: .Test::Main(string[]) Time(ms) Count P/call(ms) Method name ######################## 656.250 1 656.250 .Test::Main(string[]) Callers (with count) that contribute at least for 1%: 1 100 % System.Object::runtime_invoke_void_string[](object,intptr,intptr,intptr) ######################## 656.250 1 656.250 System.Object::runtime_invoke_void_string[](object,intptr,intptr,intptr) Callers (with count) that contribute at least for 1%: ######################## ...................(省略)其中包含整个app.exe中含有的方法总数.编译所发费的时间.
最慢的方法(通常可以看看这里有什么优化的地方没) Time(ms):The time taken in milliseconds to execute the code(总花费的时间) Count:The number of times the code has been executed(执行次数) P/call(ms):Average time spent each time this code is called(平均执行时间) Method name:The name of the method being called(方法名称)好了,如果你有时间可以用上面的方法测试下下面两段代码到底谁性能更好一些
Code 1: static void Main(string[] args) { Console.Out.WriteLine(@"Hello World!"); } Code 2: static void Main(string[] args) { Console.Out.WriteLine("Hello World!"); }