<bdo id='lfBGx'></bdo><ul id='lfBGx'></ul>

    <small id='lfBGx'></small><noframes id='lfBGx'>

    <tfoot id='lfBGx'></tfoot>
    <i id='lfBGx'><tr id='lfBGx'><dt id='lfBGx'><q id='lfBGx'><span id='lfBGx'><b id='lfBGx'><form id='lfBGx'><ins id='lfBGx'></ins><ul id='lfBGx'></ul><sub id='lfBGx'></sub></form><legend id='lfBGx'></legend><bdo id='lfBGx'><pre id='lfBGx'><center id='lfBGx'></center></pre></bdo></b><th id='lfBGx'></th></span></q></dt></tr></i><div id='lfBGx'><tfoot id='lfBGx'></tfoot><dl id='lfBGx'><fieldset id='lfBGx'></fieldset></dl></div>
  • <legend id='lfBGx'><style id='lfBGx'><dir id='lfBGx'><q id='lfBGx'></q></dir></style></legend>

        cout 或 printf 两者中哪一个具有更快的执行速度 C++?

        cout or printf which of the two has a faster execution speed C++?(cout 或 printf 两者中哪一个具有更快的执行速度 C++?)
          <tbody id='LWCZu'></tbody>
          <legend id='LWCZu'><style id='LWCZu'><dir id='LWCZu'><q id='LWCZu'></q></dir></style></legend>
          <tfoot id='LWCZu'></tfoot>

            • <i id='LWCZu'><tr id='LWCZu'><dt id='LWCZu'><q id='LWCZu'><span id='LWCZu'><b id='LWCZu'><form id='LWCZu'><ins id='LWCZu'></ins><ul id='LWCZu'></ul><sub id='LWCZu'></sub></form><legend id='LWCZu'></legend><bdo id='LWCZu'><pre id='LWCZu'><center id='LWCZu'></center></pre></bdo></b><th id='LWCZu'></th></span></q></dt></tr></i><div id='LWCZu'><tfoot id='LWCZu'></tfoot><dl id='LWCZu'><fieldset id='LWCZu'></fieldset></dl></div>
                <bdo id='LWCZu'></bdo><ul id='LWCZu'></ul>

                • <small id='LWCZu'></small><noframes id='LWCZu'>

                  本文介绍了cout 或 printf 两者中哪一个具有更快的执行速度 C++?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我已经用 C++ 编码很长时间了.我一直想知道哪个执行速度更快 printfcout ?

                  I have been coding in C++ for a long time. I always wondered which has a faster execution speed printf or cout?

                  情况:我正在用 C++ 设计一个应用程序,我有一些限制,例如执行时间限制.我的应用程序在控制台上加载了打印命令.那么哪个更可取呢?printf 还是 cout?

                  Situation: I am designing an application in C++ and I have certain constraints such as time limit for execution. My application has loads printing commands on the console. So which one would be preferable printf or cout?

                  推荐答案

                  每个都有自己的开销.根据您打印的内容,两者都可能更快.

                  Each has its own overheads. Depending on what you print, either may be faster.

                  这里有两点想到-

                  printf() 必须解析格式"字符串并对其进行操作,这会增加成本.
                  cout 有一个更复杂的继承层次结构并传递对象.

                  printf() has to parse the "format" string and act upon it, which adds a cost.
                  cout has a more complex inheritance hierarchy and passes around objects.

                  在实践中,除了最奇怪的情况外,差异应该无关紧要.如果您认为这真的很重要 - 衡量!

                  In practice, the difference shouldn't matter for all but the weirdest cases. If you think it really matters - measure!

                  编辑 -
                  哦,见鬼,我不相信我在这样做,但为了记录,在我非常具体的测试用例中,使用我非常具体的机器及其非常具体的负载,使用 MSVC 在 Release 中编译 -

                  EDIT -
                  Oh, heck, I don't believe I'm doing this, but for the record, on my very specific test case, with my very specific machine and its very specific load, compiling in Release using MSVC -

                  打印 150,000 个Hello, World!"(不使用 endl)大约需要 -
                  printf() 为 90 毫秒,cout 为 79 毫秒.

                  Printing 150,000 "Hello, World!"s (without using endl) takes about -
                  90ms for printf(), 79ms for cout.

                  打印 150,000 个随机双打大约需要 -
                  printf() 为 3450 毫秒,cout 为 3420 毫秒.

                  Printing 150,000 random doubles takes about -
                  3450ms for printf(), 3420ms for cout.

                  (平均超过 10 次运行).

                  (averaged over 10 runs).

                  差异如此之小,这可能意味着什么......

                  The differences are so slim this probably means nothing...

                  这篇关于cout 或 printf 两者中哪一个具有更快的执行速度 C++?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Is Type(::x); valid?(是类型(::x);有效的?)
                  Difference between an inline function and static inline function(内联函数和静态内联函数的区别)
                  Compilation fails randomly: quot;cannot open program databasequot;(编译随机失败:“无法打开程序数据库)
                  Too many initializers error for a simple array in bcc32(bcc32 中的简单数组的初始值设定项过多错误)
                  No Member named stoi in namespace std(命名空间 std 中没有名为 stoi 的成员)
                  Error using a constexpr as a template parameter within the same class(在同一个类中使用 constexpr 作为模板参数时出错)

                  <tfoot id='uLtU6'></tfoot>
                • <small id='uLtU6'></small><noframes id='uLtU6'>

                    <tbody id='uLtU6'></tbody>
                    • <bdo id='uLtU6'></bdo><ul id='uLtU6'></ul>
                        • <i id='uLtU6'><tr id='uLtU6'><dt id='uLtU6'><q id='uLtU6'><span id='uLtU6'><b id='uLtU6'><form id='uLtU6'><ins id='uLtU6'></ins><ul id='uLtU6'></ul><sub id='uLtU6'></sub></form><legend id='uLtU6'></legend><bdo id='uLtU6'><pre id='uLtU6'><center id='uLtU6'></center></pre></bdo></b><th id='uLtU6'></th></span></q></dt></tr></i><div id='uLtU6'><tfoot id='uLtU6'></tfoot><dl id='uLtU6'><fieldset id='uLtU6'></fieldset></dl></div>
                        • <legend id='uLtU6'><style id='uLtU6'><dir id='uLtU6'><q id='uLtU6'></q></dir></style></legend>