#include <stdio.h>#include<time.h>//clock () belongs to header fileConst intn_qsort=10000;//data size for fast rowsConst intm=20000, n=50000;//the scale of the hour and floating point operationConst intN_pi=100000000;//calculate the scale of the pi operationDoubleS_int,s_float,s_pi,s_sort;voidInt_comp (void);//Hourly ArithmeticvoidFloat_comp (void);//floating point ArithmeticvoidPi_comp (void);//Taylor series inferential calculation of PivoidQsort (intA[],intLowintHigh);//Quick-Arrange algorithmvoidQsortvoid);//functions that call the fast-line algorithmvoidPanduan ();voidPAUSE ();intMain () {printf ("------\ n Performance test started \ n"); Int_comp ();//Hourly ArithmeticFloat_comp ();//floating point ArithmeticPi_comp ();//Taylor series inferential calculation of PiQsort ();//Quick Sortprintf"------\ nthe test is over ."); printf ("hourly arithmetic score:%lf\n", S_int); printf ("Taylor series inferential Calculation pi operation score:%lf\n", S_PI); printf ("sort operation Score:%lf\n", S_sort); printf ("Total Score:%lf\n", s_int+s_float+s_pi+s_sort); Panduan (); PAUSE ();}voidInt_comp (void){//hourly Additionprintf"Hourly Operation Test (number of operations:%LF) \ n",(Double) m*N); clock_t Start,end; inti,j; Start=clock (); for(i=0; i<m;i++) for(j=0; j<n;j++); End=clock (); DoubleDuration= (Double) (End-start)/clocks_per_sec; DoubleScore= (m*n)/duration; /*Note: The score itself is the operation speed, the order of magnitude is generally in billion, for the sake of convenience, the program's scores are calculated by dividing the speed of 10,000 after the result! Except for special instructions, the back is similar! */S_int=score/10000; //printf ("The whole hour test is complete!" Score:%lf\n ", s_int);}voidFloat_comp (void){//floating point additionprintf"floating-point arithmetic test (number of operations:%LF) \ n",(Double) m*N); clock_t Start,end; floati,j; Start=clock (); for(i=0; i<m;i++) for(j=0; j<n;j++); End=clock (); DoubleDuration= (Double) (End-start)/clocks_per_sec; DoubleScore= (m*n)/duration; S_float=score/10000; //printf ("Floating point arithmetic test finished!" Score:%lf\n ", s_float);}voidPi_comp (void) {printf ("Taylor series inferential Calculation of Pi (number of operations:%d) \ n", N_PI); intM,i=1; Doubles=0; clock_t Start,end; Start=clock (); for(m=1; m<n_pi;m+=2) {s+=i* (1.0/m); I=-i; } End=clock (); DoubleDuration= (Double) (End-start)/clocks_per_sec; Doublescore=n_pi/duration; //the following line can output the calculated piprintf"pi=%lf\n",4*s); S_pi=score/10000; //printf ("Taylor series inferential calculation Pi finished!" Score:%lf\n ", S_PI);}voidQsort (intA[],intLowintHigh) {//Quick-Arrange algorithm if(Low>=high)return; intfirst=Low ; intlast=High ; intkey=A[first]; while(first<Last ) { while(First<last&&a[last]>=key)--Last ; A[first]=A[last]; while(First<last&&a[first]<=key) + +First ; A[last]=A[first]; } A[first]=key; Qsort (A,low,first-1); Qsort (A,first+1, high);}voidQsortvoid){//functions that call the fast-line algorithm intA[n_qsort],i; for(i=n_qsort;i>0; i--) a[n_qsort-1]=i; printf ("sorting operations (fast ordering of%d numbers) \ n", N_qsort);//using the worst -case scenarioclock_t Start,end; Start=clock (); Qsort (A,0, n_qsort-1); End=clock (); DoubleDuration= (Double) (End-start)/clocks_per_sec; DoubleScore= (N_qsort*n_qsort)/duration; S_sort=score/10000;//printf ("Sorting Operations test finished!" Score:%lf\n ", s_sort);}voidPanduan () {floati=s_int+s_float+s_pi+S_sort; printf ("according to the score, give Your love machine <"); if(i>0&&i<20000) {printf ("Slag Residue"); } Else if(i>20000&&i<30000) {printf ("Low End"); } Else if(i>30000&&i<40000) {printf ("Mid-end"); } Else if(i>40000&&i<50000) {printf ("High End"); } Else if(i>50000&&i<60000) {printf ("Ultra-high end"); } Else if(i>60000) {printf ("Machine King"); } printf ("> title \ n");}voidPAUSE () {Clean_stdin ();}
Pure C Language Run (detailed comment)