DebugLZQ 发表于 2012-12-10 13:24:58

【.NET程序性能分析】使用VS自带的工具分析.NET程序的性能

<div id="cnblogs_post_body">这篇博文给大家分享的是,如何使用VS自带的性能分析工具来分析我们编写的.NET程序,一边找出程序性能的瓶颈,改善代码的质量。在实际开发中,性能真的很重要,往往决定一个产品的生死~良好的用户体验的基础之一也是程序要有好的性能~
下面以一个大家熟悉比较极端的例子,来说明编写代码时考虑性能的重要性。这里DebugLZQ用的是10.0版本的VS。
示例程序代码如下:
<div class="cnblogs_code">using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace VS2010性能测试{    class Program    {      static void Main(string[] args)      {            int start = Environment.TickCount;            for (int i = 0; i < 1000; i++)            {                string s = "";                for (int j = 0; j <200; j++)                {                  s += "Outer index = ";                  s += i;                  s += " Inner index = ";                  s += j;                  s += " ";                }            }            int middle = Environment.TickCount;            Console.WriteLine("Program part1 run for {0} seconds",0.001 * (middle- start));            //            for (int i = 0; i < 1000; i++)            {                StringBuilder s = new StringBuilder();               for (int j = 0; j <200; j++)                {                  s.Append("Outer index = ");                  s.Append(i);                  s.Append("Inner index = ");                  s.Append(j);                  s.Append(" ");                }            }            int end = Environment.TickCount;            Console.WriteLine("Program part2 run for {0} seconds", 0.001 * (end - middle));            //            Console.ReadKey();      }    }}
页: [1]
查看完整版本: 【.NET程序性能分析】使用VS自带的工具分析.NET程序的性能