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;
}