The efficiency test of polynomial calculation and the efficiency of polynomial calculation
Polynomial calculation call library function Pow method and Qin Jiushao algorithm, we can measure the efficiency of their operation
Calculation function f (x) =1+ (σxi/i) (I from 1 to M);
Use the CTime time function to test the run time and bring it into the x=0.9 to calculate
#include
#include ;
#include
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--)/* Qin Jiushao polynomial algorithm */
F = f*x + 1.0/i;
Return f*x + 1.0;
}
Run time See table below
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 |
It can be seen from the results of the running time that the Qin Jiushao algorithm is much more efficient than the POW call method
http://www.bkjia.com/PHPjc/1045060.html www.bkjia.com true http://www.bkjia.com/PHPjc/1045060.html techarticle the efficiency test of polynomial calculation, polynomial calculation efficiency polynomial calculation call library function Pow method and Qin Jiushao algorithm, we calculate the efficiency of their operation F (x) =1+ (x i/i) ...