I have an application that has 4 threads. Each thread is actually a Timer and does a seperate job in specific intervals.
These threads show their logs by using Console.Writeline
.
The performance is very important in this application. I wanted to know whether removing of Console.Writeline
will tune the performance of this application or not?
Yes, executing Console.WriteLine takes a measureable amount of time.
Removing the Console.WriteLine call or changing it to a buffered background thread writing the data would really speed up the application.
However your milage might vary depending on the OS in use.
There may be two issues with Console.WriteLine in regards to performance:
IO is not typically a "fast" operation.
Calls to WriteLine are synchronized, i.e. if two threads want to write, one of them blocks on the WriteLine waiting for the other to finish writing. From MSDN on console:
I/O operations that use these streams are synchronized, which means that multiple threads can read from, or write to, the streams.
That said, the only way to understand if the time spent on Console.WriteLine has an impact on the performance of your specific application is profiling it. Otherwise it's premature optimization.
If it's for debugging purpose, you should rather use: Debug.WriteLine(..)
, because these are not included in the release version.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With