Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is Console.WriteLine a bottleneck in Windows Applications?

If I have WPF application and for debugging purposes there are messages that are being displayed on the console. Will this affect the performance of the application when its configured as a Windows Application and no console is being displayed?

like image 647
Nickolay Kondratyev Avatar asked Jul 02 '12 18:07

Nickolay Kondratyev


1 Answers

The real bottleneck in Console.WriteLine() is in actually writing to the console. Which is really expensive, particularly when the console needs to be scrolled. There is also considerable overhead in the Visual Studio hosting process capturing the output when there is no console and displaying it in the Output window instead.

Neither of which play a role after you deploy your app. But yes, all the method calls are being made and strings are getting formatted, it only falls in the bit-bucket at the last possible moment when the Windows api function finds out there is no console.

If your app has acceptable perf now, when running in the Debug build, then don't worry about it. If you see less than stellar perf in the Release build without a debugger and you think that it might be caused by Console.WriteLine() then don't hesitate to Search+Replace it to Debug.Print().

like image 54
Hans Passant Avatar answered Oct 04 '22 07:10

Hans Passant