微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

测试日期和时间函数

#include <stdio.h>
#include <time.h>
#include <math.h>
#include <ctype.h>

int main(void){
  time_t calendar_start = time(NULL);         // Initial calendar time
  clock_t cpu_start = clock();                // Initial processor time
  int count = 0;                              // Count of number of loops
  const long long iterations = 10000LL;  
  char answer = 'y';
  double x = 0.0;
  printf(Initial clock time = %lld Initial calendar time = %lld\n,(long long)cpu_start, (long long)calendar_start);
  while(tolower(answer) == 'y')
  {
    for(long long i = 0LL ; i < iterations ; ++i){
      x = sqrt(3.14159265);
    }
    printf(%lld square roots completed.\n, iterations*(++count));
    printf(Do you want to run some more(y or n)? \n);
    scanf(\n%c, &answer, sizeof(answer));
  }

  clock_t cpu_end = clock();                  // Final cpu time
  time_t calendar_end = time(NULL);           // Final calendar time

  printf(Final clock time = %lld Final calendar time = %lld\n, (long long)cpu_end, (long long)calendar_end);
  printf(CPU time for %lld iterations is %.2lf seconds\n, count*iterations, ((double)(cpu_end-cpu_start))/CLOCKS_PER_SEC);
  printf(Elapsed calendar time to execute the program is %8.2lf seconds.\n, difftime(calendar_end, calendar_start));
  return 0;
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐