对性能的影响Console.Writeline [英] Console.Writeline Effect on Performance

查看:773
本文介绍了对性能的影响Console.Writeline的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有了4 线程的应用程序。每个线程实际上是一个定时并在特定的时间间隔做了单独工作。
这些线程使用 Console.Writeline 展示自己的日志。
的性能在本申请中非常重要。我想知道,是否删除 Console.Writeline 将调整该应用程序的性能或不?


解决方案

有可能是在问候的表现为Console.WriteLine两个问题:




  1. IO不通常一个快的操作。


  2. 通话给WriteLine是同步的,也就是说,如果两个线程想要写,其中块之一上的WriteLine等着对方写完。
    MSDN上的控制台





  3. 使用这些流是同步的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:

    1. IO is not typically a "fast" operation.

    2. 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆