C + + compiler performance Comparison

Source: Internet
Author: User
Tags comparison printf sin

Now on the market, the main-C + + compiler includes m$ cl, GCC, Intel ICL, PGi PGCC and CodeGear bcc (formerly Borland Company). The most used on Windows is CL, and on a broader platform, GCC is the first choice for the C + + compiler. But when it comes to capacity optimization, rankings are not necessarily consistent with their market share.

Today, there was a comparison of compiler numerical performance. The test code is an integral program, from the Intel compiler example program, modified a header file, so that each compiler can compile.

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h

//Function to IS integrated
//Define and prototype it here
//| sin (x) |
#define INTEG_FUNC (x) Fabs (sin (x))

//Prototype timing function
Double dclock (void);

int main (void)
{
//Loop counters and number of interior points
Unsigned int i, j, N;
//Stepsize, in Dependent variable x, and accumulated sum
Double step, x_i, sum;
//Timing Variables for evaluation
Double STA RT, Finish, duration, clock_t;
//Start integral from
Double interval_begin = 0.0:
//Complete integral at
Double interval_end = 2.0 * 3 .141592653589793238;

//Start timing for the entire application
Start = Clock ();

printf ("\ n");
printf ("Number of | Computed Integral | \ n ");
printf ("Interior Points | | \ n ");
for (j=2;j<27;j++)
{
printf ("-------------------------------------\ n ");

//Compute the number of (internal rectangles + 1)
N = 1 << j;

//Compute stepsize for N-1 internal rectangles
Step = (interval_end-interval_begin)/N;

//approx. 1/2 area in rectangle:f (x0) * [STEP/2]
sum = integ_func (interval_begin) * step/2.0;

//Apply midpoint rule:
//Given length = f (x), compute the area of the
//Rectangle of width step
//Sum Areas of internal rectangle:f (xi + Step) * Step

for (i=1;i<n;i++)
{
X_i = i * step;
sum = Integ _func (x_i) * STEP;
}

//approx. 1/2 area at last Rectangle:f (XN) * [STEP/2]
sum + + integ_func (interval_end) * step/2.0;< br>
printf ("%10d | %14e | \ n ", O, sum);
}
Finish = Clock ();
Duration = (finish-start);
printf ("\ n");
printf ("Application clocks =%10e \ n ", duration);
printf ("\ n");

return 0;
}

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.