标签:alt color 指令集 def 语言 div png fun oid
#include <stdio.h> #include <stdlib.h> #include <time.h> #include <math.h> clock_t start,stop; double duration; #define MAXN 10 #define MAXK 1000000 double f1(int n, double a[], double x); double f2(int n, double a[], double x); void func(); void func() { duration = ((double)(stop-start))/CLK_TCK/MAXK; //CLK_TCK : 表示机器始终每秒所走的时钟打点数 printf("ticks = %f\n",(double)(stop - start)); printf("duration = %6.2e\n",duration); } double f1(int n, double a[], double x) { int i; double p = a[0]; for( i = 1; i < n; i++ ) { p += ( a[i] * pow( x, i) ); } return p; } double f2(int n, double a[], double x) { int i; double p = a[n]; for( i = n; i > 0; i-- ) { p = a[ i - 1 ] + x * p; } return p; } int main() { int i; double a[MAXN]; for ( i = 0; i < MAXN; i++ ) { a[i] = (double)i; } start = clock(); for( i = 0; i < MAXK; i++ ) { f1(MAXN-1, a, 1.1); } stop = clock(); printf("This is ticks1\n"); func(); start = clock(); //捕捉从程序开始运行到clock()被调用时所耗费的时间。这个时间单位是clock tick即“时钟打点” for( i = 0; i < MAXK; i++ ) { f2(MAXN-1, a, 1.1); } stop = clock(); printf("This is ticks2\n"); func(); return 0; }
标签:alt color 指令集 def 语言 div png fun oid
原文地址:https://www.cnblogs.com/gyqqqqq/p/10549387.html