岁月留声QtAsp

Qt in Linux , Asp Asp.net Jsp Php in Web

« 介绍几种内存数据库My97DatePicker是一款非常灵活好用的日期控件 »

Console.Writeline 在release 是否占用资源,解决办法

Console.Writeline in release builds a performance issue ?

http://www.pcreview.co.uk/forums/thread-2254791.php

方法一:
#if DEBUG


I couldn't help myself...

DateTime start = DateTime.Now;
for(int i=0;i<1000000;i++)
Console.WriteLine("hello there");

StreamWriter writer = new StreamWriter("time.txt");
string line = "time=" + (DateTime.Now.Ticks-start.Ticks)/10000 +
"ms";
writer.WriteLine(line);
writer.Close();

Takes about 500ms on my machine (2.8Ghz nothing special)


An easier way rather than putting lots of #if DEBUG all over your code is to
use either the:

方法二:
以下两个在Debug模式都输出,Release模式只有Trace.WriteLine 输出 ,前提是编译参数中有TRACE

System.Diagnostics.Debug.WriteLine or   多个参数没有办法,还得用方法一        
System.Diagnostics.Trace.WriteLine methods

When in debug mode both Trace and Debug will output, when in release only
trace will output, unless you remove the TRACE symbol from you compiler
options.
 

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

日历

Search

  •  

最新评论及回复

最近发表

Powered By Z-Blog 1.8 Spirit Build 80722 Code detection by Codefense

Copyright 2008-2011 京公网安备 110115000655 京ICP备09005635号 www.qtasp.cn WebSite. All Rights Reserved.