: The base and strange problem algorithm performs the addition, multiplication, non-differentiating division performance?

Source: Internet
Author: User

Base and strange question: Does the algorithm perform addition, multiplication, and non-differentiating division performance? Computer analysts consider the principle: addition, multiplication, and division to reduce computational performance, however, to what extent?

Write c using program 30 multiplied by 1 million calculated data to test the time difference, code, such as the following:

#include <stdio.h> #include <stdlib.h> #include <time.h> #define N 1000000void Add (float x[], long N) { float sum = 0;for (Long i = 0; i < n; i++) sum + = X[i];} void prod (float x[], long n) {float sum = 1;for (Long i = 0; i < n; i++) sum *= (X[i]);} void Div (float x[], long N) {for (Long i = 0; i < n; i++) {x[i]/= 3.0;}} int main () {float x[n];clock_t t1 = clock (); for (int i = 0; i <; i++) Add (x, N), clock_t t2 = Clock ();p rintf ("Million data addition time:% F seconds \ n ", (double) (T2-T1)/clocks_per_sec); t1 = clock (); for (int i = 0; i <; i++) prod (x, n) t2 = clock ();p rintf (" Million data Multiplication time:%f s \ n ", (double) (T2-T1)/clocks_per_sec), T1 = Clock (), for (int i = 0; i <; i++) div (x, n), t2 = Clock ();p rintf ( "Million Data division Time:%f sec \ n", (double) (T2-T1)/clocks_per_sec); return 0;}

The results are as follows:

Million data addition time: 0.157051 seconds
Million data multiplication time: 0.184712 seconds
Million Data division time: 0.161014 seconds
-----------------------------------------
When adding millions of of the data to: 0.156099 second
Multiply data points with time: 0.184023 second
When hundreds of millions of data are divided by: 0.159588 second


What's the problem?

It should be said that the algorithm no longer distinguishes basic operations?

: The base and strange problem algorithm performs the addition, multiplication, non-differentiating division performance?

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.