zoukankan      html  css  js  c++  java
  • .NET : 使用代码性能分析工具

    上一篇,我演示了如何使用CLR Profiler对.NET应用程序进行性能分析。下面再谈谈在Visual Studio中自带的工具

    示范代码

    using System;
    using System.Text;
    /// <summary>
    /// 这个例子程序用来演示如何进行.NET程序的性能监视和调优
    /// 作者:陈希章
    /// </summary>
    public class ProfilerSample1
    {
        static void Main(string[] args)
        {
            int start = Environment.TickCount;
            for (int i = 0; i < 1000; i++)
            {
                string s = "";
                for (int j = 0; j < 100; j++)
                {
                    s += "Outer index = ";
                    s += i;
                    s += " Inner index = ";
                    s += j;
                    s += " ";
                }
            }
    
            #endregion
    
    
            Console.WriteLine("Program ran for {0} seconds",
                0.001 * (Environment.TickCount - start));
        }
    }

    image

    运行代码分析工具(需要Visual Studio Team suite for developer版本)

    "分析"==〉“启动性能向导”

    image

    image

    image

    image

    现在可以启动性能监视了,很快就能看到下面的一个报表

    image

    通过这个摘要报告,我们可以看出来,该程序中占绝大部分的操作都是string.concat方法,就是字符串连接。一共有500000次。

    从时间上也可以看到它们占用了绝大部分时间

    image

    image

    image

    将程序修改为使用stringbuidler

    image

    image

  • 相关阅读:
    关于一位程序员入门的面试经验
    Outpro的博客测试
    优先队列
    linux (centos 6.2)在输入查询或者操作命令时提示-bash: fork: cannot allocate memory
    win10下JDK环境变量
    Mac OS如何安装IDEA
    解决下载github代码慢的问题
    vue 模板语法之指令
    vue的基本介绍以及第一个程序
    消息中间的几大应用场景
  • 原文地址:https://www.cnblogs.com/chenxizhang/p/1623079.html
Copyright © 2011-2022 走看看