<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()` 函数只返回一个零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  How to print vector#39;s data(如何打印矢量的数据)
                  Visual C++ appends 0xCC (int3) bytes at the end of functions(Visual C++ 在函数末尾附加 0xCC (int3) 字节)
                  How to use a variable inside a _T wrapper?(如何在 _T 包装器中使用变量?)
                  MSVC++ warning flags(MSVC++ 警告标志)
                  How to read file which contains uxxxx in vc++(如何在vc++中读取包含uxxxx的文件)
                  stack overflow error in C++ program(C++程序中的堆栈溢出错误)
                  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>