C语言——计算执行时间2018-06-26

前言

之前的超级斐波那契数列算法题,用python写了几个版本,但速度太慢,改写成C语言,此时需要计算C的执行时间

代码

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
/*
  Fib func's code
*/
int main(){
    // int n = 2000000000;
    // unsigned long n = 4611686018427387904;
    // int n = 300000000;
    int n = 900000;
    unsigned long _Fib[5] = {1,1,1,1,1};
    // scanf("input");
    // printf("%d\n",b );
    printf("\ntest start:\n");
    // test run time
    clock_t begin,end;
    // start to log time
    begin = clock();
    unsigned long mod;
    mod = Fib(n, _Fib);
    // end time
    end = clock();
    double cost = (double)(end - begin)/CLOCKS_PER_SEC;
    // Fib(n);
    printf("the running time is %lf secs\n", cost);
    printf("mod value:\n%lu\n\n", mod);

    return 0;
    
}

运行效果

image.png

参考

C语言--计算程序执行时间 3种方法

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容