1. <legend id='VyBkp'><style id='VyBkp'><dir id='VyBkp'><q id='VyBkp'></q></dir></style></legend>
      <tfoot id='VyBkp'></tfoot>

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

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

        如何对 C++ 代码的性能进行基准测试?

        时间:2023-10-07
          <tbody id='bbpgX'></tbody>

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

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

            1. <legend id='bbpgX'><style id='bbpgX'><dir id='bbpgX'><q id='bbpgX'></q></dir></style></legend>
                1. 本文介绍了如何对 C++ 代码的性能进行基准测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我开始认真地研究算法和数据结构,并且有兴趣学习如何比较实现 A&DT 的不同方式的性能.

                  I am starting to study algorithms and data structures seriously, and interested in learning how to compare the performance of the different ways I can implement A&DTs.

                  对于简单的测试,我可以获取某件事运行之前/之后的时间,运行那件事 10^5 次,然后平均运行时间.我可以按大小参数化输入,或对随机输入进行抽样,并获得运行时间与输入大小的列表.我可以将其输出为 csv 文件,然后将其输入到 Pandas 中.

                  For simple tests, I can get the time before/after something runs, run that thing 10^5 times, and average the running times. I can parametrize input by size, or sample random input, and get a list of running times vs. input size. I can output that as a csv file, and feed it into pandas.

                  我不确定是否有任何警告.我也不知道如何衡量空间复杂度.

                  I am not sure there are no caveats. I am also not sure what to do about measuring space complexity.

                  我正在学习用 C++ 编程.是否有人性化的工具来实现我的目标?

                  I am learning to program in C++. Are there humane tools to achieve what I am trying to do?

                  推荐答案

                  对代码进行基准测试并不容易.我发现最有用的是 Google 基准库. 即使您不打算使用它,它也可能是很高兴阅读一些例子.它有很多可能性来参数化测试,将结果输出到文件,甚至返回算法的大 O 符号复杂度(仅举几个例子).如果您熟悉 Google 测试框架,我建议您使用它.它还使编译器优化成为可能,因此您可以确保您的代码没有被优化掉.

                  Benchmarking code is not easy. What I found most useful was Google benchmark library. Even if you are not planning to use it, it might be good to read some of examples. It has a lot of possibilities to parametrize test, output results to file and even returning you Big O notation complexity of your algorithm (to name just few of them). If you are any familiar with Google test framework I would recommend you to use it. It also keeps compiler optimization possible to manage so you can be sure that your code wasn't optimized away.

                  在 CppCon 2015: Chandler Carruth "Tuning C++: Benchmarks,和 CPU 和编译器!天哪!".您可能犯的错误有很多见解(它还使用谷歌基准)

                  There is also great talk about benchmarking code on CppCon 2015: Chandler Carruth "Tuning C++: Benchmarks, and CPUs, and Compilers! Oh My!". There are many insights in possible mistake that you can make (it also uses google benchmark)

                  这篇关于如何对 C++ 代码的性能进行基准测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:在 C++ 或 C 中寻找基于磁盘的 B+ 树实现 下一篇:在 C++ 中,我可以从结构派生一个类吗

                  相关文章

                  最新文章

                2. <small id='Tf9Vm'></small><noframes id='Tf9Vm'>

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