Efficiency Test for Polynomial Calculations
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.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

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.

Solution to docker start failure: 1. Check the running status, and then release the occupied memory through the "echo 3 > /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.

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

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 .

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 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.

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.
