#include<bits/stdc++.h>
#include<windows.h>
#define maxn 10
using namespace std;
int f1(int n, double a[], double x);
int f2(int n, double a[], double x);
int 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;
}
int f2(int n, double a[], double x){
int i ;
double p = a[n];
for(i = n; i>=1;i-- )
p = a[n-1] + i*p;
return p;
}
int main()
{
double a[maxn];
for(int i = 0; i < maxn; i++)
a[i] = double(i);
double run_time;
LARGE_INTEGER time_start;
LARGE_INTEGER time_over;
double dqFreq;
LARGE_INTEGER f;
QueryPerformanceFrequency(&f);
dqFreq=(double)f.QuadPart;
QueryPerformanceCounter(&time_start);
f1( maxn-1, a, 1.1);
QueryPerformanceCounter(&time_over);
run_time=1000000*(time_over.QuadPart-time_start.QuadPart)/dqFreq;
printf("run_time:%fus\n",run_time);
double run_time1;
LARGE_INTEGER time_start1;
LARGE_INTEGER time_over1;
double dqFreq1;
LARGE_INTEGER f1;
QueryPerformanceFrequency(&f1);
dqFreq1=(double)f1.QuadPart;
QueryPerformanceCounter(&time_start1);
f2( maxn-1, a, 1.1);
QueryPerformanceCounter(&time_over1);
run_time1=1000000*(time_over1.QuadPart-time_start1.QuadPart)/dqFreq1;
printf("run_time1:%fus\n",run_time1);
return 0;
}