我有了4 线程的应用程序。每个线程实际上是一个定时并在特定的时间间隔做了单独工作。 这些线程使用 Console.Writeline 展示自己的日志。 的性能在本申请中非常重要。我想知道,是否删除 Console.Writeline 将调整该应用程序的性能或不?
解决方案有可能是在问候的表现为Console.WriteLine两个问题:
IO不通常一个快的操作。
通话给WriteLine是同步的,也就是说,如果两个线程想要写,其中块之一上的WriteLine等着对方写完。 从 MSDN上的控制台:
使用这些流是同步的I / O操作,这意味着多个线程可以读取,或者写不出来,流。
这是说,了解的唯一方式,如果用在Console.WriteLine时间对影响您的特定应用的性能分析它。否则,它过早的优化。
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?
解决方案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.
更多推荐
对性能的影响Console.Writeline
发布评论