Console.Write in Release mode

F

Franco, Gustavo

Hi,

Console.WriteLine does something on Release mode?

I have many of them in my application and I want to know if the performace
could be affected, on debug mode I can see a big difference between having
and not because I'm printing many of them on loops, etc.

Now, in Release mode Console.Writeline has something like #if (!Release),
send the string to something like "/dev/null" or it is executed internally
like a normal instruction.

Thanks,
Gustavo.
 
M

Mattias Sjögren

Gustavo,
Console.WriteLine does something on Release mode?

Yes, how else would you write to the console in a release build?

You may want to look at Debug.WriteLine() instead, or wrap the
Console.WriteLine call in your own method that's decorated with
[Conditional("DEBUG")], or put the WriteLine calls inside #if DEBUG
#endif.



Mattias
 
C

Cezary Nolewajka

Another good idea is to use the Trace class, when you can decide during the
runtime of the Release, if the output is directed to anywhere using the
<trace> element of the application .config file.You can even declare your
own classes as output sinks using the <listeners> element.

Have a look at the following links:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/gngrftraceelement.asp
http://msdn.microsoft.com/library/d...en-us/cpgenref/html/gngrflistenerselement.asp

A higher level runtime tracing tool is EIF (Enterprise Instrumentation
Framework):
http://www.microsoft.com/technet/tr...itsolutions/net/maintain/opnetapp/default.asp

Cezary Nolewajka
mailto:[email protected]
remove all "no-sp-am-eh"s to reply

Mattias Sjögren said:
Gustavo,
Console.WriteLine does something on Release mode?

Yes, how else would you write to the console in a release build?

You may want to look at Debug.WriteLine() instead, or wrap the
Console.WriteLine call in your own method that's decorated with
[Conditional("DEBUG")], or put the WriteLine calls inside #if DEBUG
#endif.



Mattias
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top