YES/NO: Console.WriteLine use a lot of resources?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

does this command use a lot of resources? should i comment them all out
before creating my .exe file? i use it a lot for debugging...

or, does it not make much of a difference?

thanks much
 
Wrap your code into a method:


public static void MyConsoleWrite ( string msg )
{
Console.Writeline ( msg ) ;
}


Then you only have 1 place to comment out the code.


public static void MyConsoleWrite ( string msg )
{
//Console.Writeline ( msg ) ;
}


//this is the non debug version
public static void MyConsoleWrite ( string msg , bool alwaysWrite )
{

if ( alwaysWrite )
{

Console.Writeline ( msg ) ;

}
}





//this is the non debug version
public static void MyConsoleWrite ( string msg , bool alwaysWrite )
{

// if ( alwaysWrite ) //aka ignore the bool flag and always write it
out
//{

Console.Writeline ( msg ) ;

//}
}
 
If you are using it for debugging, and you are providing a release
version, then it's not really a resource issue, but rather, you have code
which is not appropriate for a release version.

That being said, WriteLine doesn't consume resources, but if you call it
a significant number of times, you are going to impact the performance of
your system.

Instead of using Console.WriteLine for debugging, why not use the static
WriteLine methods on the Debug class? You can attach listeners to the Debug
class and have the output sent anywhere you wish (including the console) and
in your release app, the calls won't be made.
 
No. But it does perform I/O blocking as there's a lot of synchronousity with
command line I/O. It shouldn't slow down the kernel from multiprocessing but
it will likely slow down your own app just to pump text to your console
window.

Jon
 
R said:
does this command use a lot of resources? should i comment them all out
before creating my .exe file? i use it a lot for debugging...

or, does it not make much of a difference?

Look at a real logging framework like log4net.

Arne
 

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

Back
Top