C++编译器性能对比[VC/C++编程]
本文“C++编译器性能对比[VC/C++编程]”是由七道奇为您精心收集,来源于网络转载,文章版权归文章作者所有,本站不对其观点以及内容做任何评价,请读者自行判断,以下是其具体内容:
目前市面上,主流的C/C++编译器包含M$的CL、gcc、Intel的icl、PGI的pgcc及Codegear的bcc(本来属于Borland公司).Windows上利用最多的自然是cl,而在更广漠的平台上,gcc则是C/C++编译器的首选.但要提到本领优化,排名就未必与它们的市场占据率一致了.
本日一时髦起,便做了一个各编译器数值性能的对比.测试的代码是一个求积分的程序,根源于intel编译器的例子程序,改正了一个头文件,以便每个编译器都能编译.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
// Function to be 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, independent variable x, and accumulated sum
double step, x_i, sum;
// Timing variables for evaluation
double start, 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 first 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 in last rectangle: f(xN) * [step/2]
sum += INTEG_FUNC(interval_end) * step / 2.0;
printf(" %10d | %14e | \n", N, sum);
}
finish = clock();
duration = (finish - start);
printf(" \n");
printf(" Application Clocks = %10e \n", duration);
printf(" \n");
return 0;
}
以上是“C++编译器性能对比[VC/C++编程]”的内容,如果你对以上该文章内容感兴趣,你可以看看七道奇为您推荐以下文章:
本文地址: | 与您的QQ/BBS好友分享! |