【问题标题】:HOW I CALCULATE TIME IN C PROGRAM我如何在 C 程序中计算时间
【发布时间】:2015-09-20 07:58:36
【问题描述】:

我如何在 c 程序中计算实时......

__________________________开始=时钟(); ----------------------------------------end=clock();

diff=end-start;

开始=124682129.0000000 结束 =124682129.0000000 diff的结果值为0.0000000000000000000000

我正在对一个数组进行排序,我想在 gcc 编译器中计算排序前和排序结束的时间......

我如何计算这些时间? 即时的 执行时间

【问题讨论】:

标签: c linux time parallel-processing


【解决方案1】:

如果你想得到你的程序的执行时间,你可以这样做:

//some code
#include <time.h>

int main () { 
    double seconds;
    time_t started=time(NULL);
    RunSomeFunc();
    seconds=difftime(time(NULL),started);
    //more code
}

在这里您正在测量RunSomeFunc 的执行时间。


文档

【讨论】:

    【解决方案2】:

    用C打印时间的简单程序

    /* localtime example */
    #include <stdio.h>
    #include <time.h>
    
    int main ()
    {
      time_t rawtime;
      struct tm * timeinfo;
    
      time ( &rawtime );
      timeinfo = localtime ( &rawtime );
      printf ( "Current local time and date: %s", asctime (timeinfo) );
    
      return 0;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多