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

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

          <bdo id='y9M5j'></bdo><ul id='y9M5j'></ul>
      1. <i id='y9M5j'><tr id='y9M5j'><dt id='y9M5j'><q id='y9M5j'><span id='y9M5j'><b id='y9M5j'><form id='y9M5j'><ins id='y9M5j'></ins><ul id='y9M5j'></ul><sub id='y9M5j'></sub></form><legend id='y9M5j'></legend><bdo id='y9M5j'><pre id='y9M5j'><center id='y9M5j'></center></pre></bdo></b><th id='y9M5j'></th></span></q></dt></tr></i><div id='y9M5j'><tfoot id='y9M5j'></tfoot><dl id='y9M5j'><fieldset id='y9M5j'></fieldset></dl></div>
      2. C `clock()` 函数只返回一个零

        The C `clock()` function just returns a zero(C `clock()` 函数只返回一个零)

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

                <tbody id='jck0a'></tbody>
              1. <tfoot id='jck0a'></tfoot>

                  <bdo id='jck0a'></bdo><ul id='jck0a'></ul>
                • 本文介绍了C `clock()` 函数只返回一个零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  C clock() 函数只返回零.我尝试使用不同的类型,但没有任何改进......这是一种以高精度测量时间的好方法吗?

                  #include #include int main(){clock_t 开始,结束;双 cpu_time_used;字符 [32];开始 = 时钟();printf("
                  睡眠 3 秒...
                  
                  ");睡眠(3);结束 = 时钟();cpu_time_used = ((double)(end - start))/((double)CLOCKS_PER_SEC);printf("start = %.20f
                  end = %.20f
                  ", start, end);printf("delta = %.20f
                  ", ((double) (end - start)));printf("cpu_time_used = %.15f
                  ", cpu_time_used);printf("CLOCKS_PER_SEC = %i
                  
                  ", CLOCKS_PER_SEC);返回0;}

                  <块引用>

                  睡眠3秒...开始 = 0.00000000000000000000结束 = 0.00000000000000000000增量 = 0.00000000000000000000cpu_time_used = 0.000000000000000CLOCKS_PER_SEC = 1000000

                  平台:Intel 32 位,RedHat Linux,gcc 3.4.6

                  解决方案

                  clock() 报告 CPU 使用时间.sleep() 不使用任何 CPU 时间.所以你的结果可能完全正确,只是不是你想要的.

                  The C clock() function just returns me a zero. I tried using different types, with no improvement... Is this a good way to measure time with good precision?

                  #include <time.h>
                  #include <stdio.h>
                  
                  int main()
                  {
                      clock_t start, end;
                      double cpu_time_used;
                  
                      char s[32];
                  
                      start = clock();
                  
                      printf("
                  Sleeping 3 seconds...
                  
                  ");
                      sleep(3);
                  
                      end = clock();
                  
                      cpu_time_used = ((double)(end - start)) / ((double)CLOCKS_PER_SEC);
                  
                      printf("start = %.20f
                  end   = %.20f
                  ", start, end);
                      printf("delta = %.20f
                  ", ((double) (end - start)));
                      printf("cpu_time_used  = %.15f
                  ", cpu_time_used);
                      printf("CLOCKS_PER_SEC = %i
                  
                  ", CLOCKS_PER_SEC);
                  
                      return 0;
                  }
                  

                  Sleeping 3 seconds...
                  
                  start = 0.00000000000000000000
                  end   = 0.00000000000000000000
                  delta = 0.00000000000000000000
                  cpu_time_used  = 0.000000000000000
                  CLOCKS_PER_SEC = 1000000
                  

                  Platform: Intel 32 bit, RedHat Linux, gcc 3.4.6

                  解决方案

                  clock() reports CPU time used. sleep() doesn't use any CPU time. So your result is probably exactly correct, just not what you want.

                  这篇关于C `clock()` 函数只返回一个零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  Unable to access non-const member functions of objects in C++ std::set(无法访问 C++ std::set 中对象的非常量成员函数)
                  Constructing std::function argument from lambda(从 lambda 构造 std::function 参数)
                  STL BigInt class implementation(STL BigInt 类实现)
                  Sync is unreliable using std::atomic and std::condition_variable(使用 std::atomic 和 std::condition_variable 同步不可靠)
                  Move list element to the end in STL(在 STL 中将列表元素移动到末尾)
                  Why is overloading operatoramp;() prohibited for classes stored in STL containers?(为什么禁止对存储在 STL 容器中的类重载 operatoramp;()?)
                  1. <tfoot id='lYtEo'></tfoot>
                  2. <legend id='lYtEo'><style id='lYtEo'><dir id='lYtEo'><q id='lYtEo'></q></dir></style></legend>
                  3. <small id='lYtEo'></small><noframes id='lYtEo'>

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