<bdo id='UJFYr'></bdo><ul id='UJFYr'></ul>
  • <small id='UJFYr'></small><noframes id='UJFYr'>

      <tfoot id='UJFYr'></tfoot><legend id='UJFYr'><style id='UJFYr'><dir id='UJFYr'><q id='UJFYr'></q></dir></style></legend>

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

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

        时间:2023-06-04
        <i id='5drnz'><tr id='5drnz'><dt id='5drnz'><q id='5drnz'><span id='5drnz'><b id='5drnz'><form id='5drnz'><ins id='5drnz'></ins><ul id='5drnz'></ul><sub id='5drnz'></sub></form><legend id='5drnz'></legend><bdo id='5drnz'><pre id='5drnz'><center id='5drnz'></center></pre></bdo></b><th id='5drnz'></th></span></q></dt></tr></i><div id='5drnz'><tfoot id='5drnz'></tfoot><dl id='5drnz'><fieldset id='5drnz'></fieldset></dl></div>
      1. <tfoot id='5drnz'></tfoot>
          <tbody id='5drnz'></tbody>

                • <bdo id='5drnz'></bdo><ul id='5drnz'></ul>
                • <small id='5drnz'></small><noframes id='5drnz'>

                  <legend id='5drnz'><style id='5drnz'><dir id='5drnz'><q id='5drnz'></q></dir></style></legend>

                • 本文介绍了如何对 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++ 代码的性能进行基准测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文章

                • <legend id='KFsP6'><style id='KFsP6'><dir id='KFsP6'><q id='KFsP6'></q></dir></style></legend>
                    <bdo id='KFsP6'></bdo><ul id='KFsP6'></ul>

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

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