前言
之前的超级斐波那契数列算法题,用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;
}
运行效果
参考
C语言--计算程序执行时间 3种方法