Home Backend Development PHP Tutorial Efficiency Test for Polynomial Calculations

Efficiency Test for Polynomial Calculations

Jul 30, 2016 pm 01:32 PM
clock double lt start stop

Polynomial calculation calls the library function pow method and Qin Jiutao algorithm. Let’s measure their operating efficiency

Calculation function f(x)=1+(Σxi/i)(i is taken from 1 to m);

Use the ctime time function to test the running time, and bring 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 Jiuchao polynomial algorithm*/
f = f*x + 1.0 / i;
return f*x + 1.0;
}

See the table below for the running time

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.0 49 0.472 4.706

It can be seen from the running time results , Qin Jiushao algorithm is much more efficient than the pow calling method

The above has introduced the efficiency test of polynomial calculations, including aspects of it. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to solve the blue screen of win11 clock watchdog timeout? How to solve the blue screen of win11 clock watchdog timeout? Feb 14, 2024 pm 04:00 PM

Many users will experience a blue screen after upgrading the win11 system, such as: clockwatchdogtimeout blue screen, so how to solve this? Users can update the driver or check for overheating problems, etc. Let this site carefully introduce to users the solution to the clockwatchdogtimeout blue screen win11. Solution to the clockwatchdogtimeout blue screen win11 1. Update the driver: Updating the CPU and motherboard drivers may solve the problem. You can download the latest drivers by visiting the manufacturer's website. 2. Check for overheating issues: Overheating may also be one of the causes of this error.

What should I do if docker start cannot start? What should I do if docker start cannot start? Oct 21, 2022 pm 03:43 PM

Solution to docker start failure: 1. Check the running status, and then release the occupied memory through the "echo 3 &gt; /proc/sys/vm/drop_caches" command; 2. Use "$netstat -nltp|grep .. ." command to check whether the port has been occupied. If it is found to be occupied after going online, change it to an available port and restart.

C++ program to convert double type variable to int type C++ program to convert double type variable to int type Aug 25, 2023 pm 08:25 PM

In C++, variables of type int can only hold positive or negative integer values; they cannot hold decimal values. There are float and double values ​​available for this purpose. The double data type was created to store decimals up to seven digits after the decimal point. Conversion of an integer to a double data type can be done automatically by the compiler (called an "implicit" conversion), or it can be explicitly requested by the programmer from the compiler (called an "explicit" conversion). In the following sections, we'll cover various conversion methods. Implicit conversions The compiler performs implicit type conversions automatically. To achieve this, two variables are required - one of floating point type and the other of integer type. When we simply assign a floating point value or variable to an integer variable, the compiler takes care of all the other things

php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决 php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决 Jun 13, 2016 am 10:23 AM

php提交表单通过后,弹出的对话框怎样在当前页弹出php提交表单通过后,弹出的对话框怎样在当前页弹出而不是在空白页弹出?想实现这样的效果:而不是空白页弹出:------解决方案--------------------如果你的验证用PHP在后端,那么就用Ajax;仅供参考:HTML code

How many bytes does double occupy? How many bytes does double occupy? Dec 25, 2020 am 10:36 AM

The bytes occupied by double: 1. Under a 16-bit compiler, double occupies 8 bytes; 2. Under a 32-bit compiler, double occupies 8 bytes; 3. Under a 64-bit compiler, double occupies 8 bytes .

What to do if node start reports an error What to do if node start reports an error Dec 29, 2022 pm 01:55 PM

Solution to node start error: 1. Execute "node xx.js" directly in the terminal; 2. Add start startup item "scripts": {"test": "echo \"Error: no test specified\" && exit 1 ","start":"node service.js"}"; 3. Re-execute "npm start".

How to solve the blue screen display stop 0x00000c4 on win7 computer? How to solve the blue screen display stop 0x00000c4 on win7 computer? Feb 11, 2024 pm 06:54 PM

How to solve the blue screen display stop0x00000c4 on win7 computer? Many users have a blue screen problem when using the win7 system, which makes many operations unavailable and often requires restarting the computer. So how to solve the blue screen stop0x00000c4? Today the editor of the win7 tutorial will share with you the detailed solution. , let’s find out together. How to solve the blue screen display stop0x00000c4 on win7 computer. Solution 1: 1. Restart the computer, hold down the F8 key, and start in safe mode. 2. After entering the interface, delete the mismatched drivers and third-party software. 3. Use anti-virus software to scan and kill viruses on your computer, and then restart your computer, which is usually fine. 4.

What is the difference between float and double What is the difference between float and double Oct 11, 2023 pm 05:38 PM

The main differences between float and double lie in precision, storage and calculation speed, range, and use in programming languages. Detailed introduction: 1. The precision is different. Float is a single-precision floating point number, occupying 4 bytes (32 bits), while double is a double-precision floating point number, occupying 8 bytes (64 bits); 2. The storage and calculation speed are different. , double takes up more space and requires more storage space to store values. In applications that require high performance and speed, it may be more efficient to use the float type; 3. Different ranges, etc.

See all articles