資料結構與演算法1-2 C語言已耗用時間檢測演算法

來源:互聯網
上載者:User

標籤:star   logs   bsp   stdio.h   時間   pow   std   int   clu   

 1 #include <stdio.h> 2 #include <math.h> 3 #include <time.h> 4  5 clock_t start,stop; 6 #define max 1e7 7 #define num 100
8 void putin(double *); 9 void f(double *,int ,double );10 void ff(double *a,int n,double x);11 void timetext(void (*point)(double *,int,double),double *,int ,double);
12 void main()13 {14 double a[num];15 putin(a);16 timetext(f,a,num,1.1);17 timetext(ff,a,num,1.1);18 19 }20 21 22 void putin(double *a)23 { int i;24 for(i=0;i<num;i++)25 *(a+i)=(double)i;26 }27 28 void f(double *a,int n,double x)29 { int i;30 double sum=0;31 for(i=0;i<n;i++)32 sum=sum+a[i]*pow(x,i);33 34 }35 36 void ff(double *a,int n,double x)37 { int i;38 double sum=a[n-1];39 for(i=n-2;i>=0;i--)40 sum=sum*x+a[i];41 }42 43 void timetext(void (*point)(double *,int,double),double *a,int n,double x)44 {45 int i;46 double duration;47 start=clock();48 for(i=0;i<max;i++)49 (*point)(a,n,x);50 stop=clock();51 duration=((double)(stop-start))/max/CLK_TCK;52 printf("%f\n",duration);53 printf("%f\n",(double)(stop-start));54 printf("\n");55 }

 

資料結構與演算法1-2 C語言已耗用時間檢測演算法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.