本篇文章小编为大家介绍,关于VS2012自带的 性能分析 工具使用实例(图文介绍),需要的朋友参考下
本篇通过一小段代码的console程序来进行性能的分析以及改进、直到后面的改进前、改进后性能比较结果。
先看console代码(源代码下载):
{
int i = 10000;
while(i–>0)
{
Core c=new Core();
c.Process(DateTime.Now.ToString());
}
}
public class Core
{
public void Process(string input)
{
//process logic
string result = string.Format(“{0}-{1}”, DateTime.Now, input);
//log to file
Log(result);
}
public void Log(string message)
{
string fileName = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, “log.txt”);
string msg = “{Now}: {Message}”;
msg = msg.Replace(“{Now}”, DateTime.Now.ToString(“yyyy-MM-dd HH:mm:ss”));
msg = msg.Replace(“{Message}”, message);
using (StreamWriter sw = System.IO.File.AppendText(fileName))
{
sw.Wri来源gaodai#ma#com搞*代#码网teLine(msg);
sw.Flush();
sw.Close();
}
}
}
以上就是关于VS2012自带的 性能分析 工具使用实例(图文介绍)的详细内容,更多请关注gaodaima搞代码网其它相关文章!