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.