C 编译器性能比较计算机二级考试
文章作者 100test 发表时间 2009:06:15 10:08:32
来源 100Test.Com百考试题网
编辑特别推荐:
全国计算机等级考试(等考)指定教材
全国计算机等级考试学习视频
全国计算机等级考试网上辅导招生
全国计算机等级考试时间及科目预告
百考试题教育全国计算机等级考试在线测试平台
全国计算机等级考试资料下载
全国计算机等级考试论坛
计算机等级考试四级应用题解析汇总
2009年下半年全国计算机二级考试报名时间从6月1日起已经开始报名。详情点击:2009年下半年全国计算机等级考试各地报名点汇总。2009年下半年全国计算机二级考试时间是2009年9月19日至23日。更多优质资料尽在百考试题论坛 百考试题在线题库。
现在市面上,主流的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