Test the efficiency of Polynomial computing and the efficiency of Polynomial computing

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.