对性能的影响Console.Writeline

编程入门 行业动态 更新时间:2024-10-24 20:13:21
本文介绍了对性能的影响Console.Writeline的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有了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

    本文发布于:2023-11-05 09:25:07,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1560458.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:性能   Console   Writeline

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!