Test the efficiency of Polynomial computing and the efficiency of Polynomial computing
The pow method and the qinjiu algorithm of Polynomial computing call library function are used to calculate their operation efficiency.
Calculation function f (x) = 1 + (Σ xi/I) (I get from 1 to m );
Use the ctime function to test the running time, which is calculated by x = 0.9.
# Include <iostream>
# Include <cmath>;
# Include <ctime>
Using namespace std;
Double Fn1 (double x );
Double Fn2 (double x );
# Define m 1000000000
Clock_t start, stop;
Int main (){
Double x;
X = 0.9;
Start = clock ();
Cout <Fn1 (x) <endl;
Stop = clock ();
Cout <double (stop-start)/CLK_TCK <endl;
//-----------------------------------
Start = clock ();
Cout <Fn2 (x) <endl;
Stop = clock ();
Cout <double (stop-start)/CLK_TCK <endl;
Return 0;
}
Double Fn1 (double x ){
Int I;
Double f = 1.0;
For (I = 1; I <= m; I ++)
F + = pow (x, I)/I;
Return f;
}
Double Fn2 (double x ){
Int I;
Double f = 0.0;
For (I = m; I> = 1; I --)/* qinjiu polynomial algorithm */
F = f * x + 1.0/I;
Return f * x + 1.0;
}
For the running time, see the following table.
M |
100 |
1000 |
10000 |
100000 |
1000000 |
10000000 |
1000000 |
1000000000 |
Fn1 |
0.001 |
0.001 |
0.003 |
0.015 |
0.157 |
1.619 |
17.955 |
191.608 |
Fn2 |
0 |
0 |
0 |
0.001 |
0.005 |
0.049 |
0.472 |
4.706 |
According to the running time, the efficiency of the qinjiu algorithm is much higher than that of the pow method.