Test the efficiency of polynomial computation and the efficiency of polynomial computation

Source: Internet
Author: User
Test the efficiency of polynomial computing and the efficiency of polynomial computing. The efficiency test of polynomial computing, the polynomial computing efficiency, the pow method of the library function called by the polynomial computing, and the Qin Jiuyun algorithm are used to calculate the operating efficiency of the computing functions f (x) 1 + (xii) 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
# 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 --)/* 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.

Polynomial computing calls the database function pow method and the Qin Jiuyun algorithm. let's calculate their operation efficiency. the computing function f (x) = 1 + (x I/I )...

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.