• <legend id='7h3FN'><style id='7h3FN'><dir id='7h3FN'><q id='7h3FN'></q></dir></style></legend>
  • <tfoot id='7h3FN'></tfoot>

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

      1. <small id='7h3FN'></small><noframes id='7h3FN'>

        精确的时间测量

        时间:2023-05-23
        1. <small id='0jCWw'></small><noframes id='0jCWw'>

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

                • <tfoot id='0jCWw'></tfoot>
                • 本文介绍了精确的时间测量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我在 C++ 中使用 time.h 来测量函数的计时.

                  I'm using time.h in C++ to measure the timing of a function.

                  clock_t t = clock();
                  someFunction();
                  printf("
                  Time taken: %.4fs
                  ", (float)(clock() - t)/CLOCKS_PER_SEC);
                  

                  但是,我总是将时间设为 0.0000.clock() 和 t 在单独打印时具有相同的值.我想知道是否有办法在 C++ 中精确测量时间(可能以纳秒为单位).我使用的是 VS2010.

                  however, I'm always getting the time taken as 0.0000. clock() and t when printed separately, have the same value. I would like to know if there is way to measure the time precisely (maybe in the order of nanoseconds) in C++ . I'm using VS2010.

                  推荐答案

                  我通常使用 QueryPerformanceCounter 函数.

                  I usually use the QueryPerformanceCounter function.

                  示例:

                  LARGE_INTEGER frequency;        // ticks per second
                  LARGE_INTEGER t1, t2;           // ticks
                  double elapsedTime;
                  
                  // get ticks per second
                  QueryPerformanceFrequency(&frequency);
                  
                  // start timer
                  QueryPerformanceCounter(&t1);
                  
                  // do something
                  ...
                  
                  // stop timer
                  QueryPerformanceCounter(&t2);
                  
                  // compute and print the elapsed time in millisec
                  elapsedTime = (t2.QuadPart - t1.QuadPart) * 1000.0 / frequency.QuadPart;
                  

                  这篇关于精确的时间测量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何在 C++ 中覆盖 cout? 下一篇:C++11 中是否有并发容器?

                  相关文章

                  最新文章

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

                  1. <small id='c6EKR'></small><noframes id='c6EKR'>

                  2. <legend id='c6EKR'><style id='c6EKR'><dir id='c6EKR'><q id='c6EKR'></q></dir></style></legend>
                        <bdo id='c6EKR'></bdo><ul id='c6EKR'></ul>

                      <tfoot id='c6EKR'></tfoot>