文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>编译器优化性能初步比较

编译器优化性能初步比较

时间:2010-08-26  来源:PcX

OS:Windows XP 32 bit

CPU:Intel Mobile Core 2 Duo T6600

一、混合四则运算

main.c

#include <stdio.h>
#include <time.h>
int main()
{
      int i,j,a=1,b=1;
      float c=1.0,d=1.0;
      double e=1.0,f=1.0;
      double start, finish, duration;
      start=clock();
      for (i = 0; i < 1000; i++)
      {
            for (j = 0; j < 1000000; j++)
            {
                  a = a + 50;
                  b = a - 100;
                  a = b * 20;
                  c = a + 300.89;
                  d = c - 600.89;
                  c = d * 90.89;
                  d = c / 55.89;
                  e = c * 90.89;
                  f = e / 55.89;
            }
      }
      finish=clock();
      duration=finish-start;
      printf("%f,%f\n",e,f);
      printf("%10e",duration);
      return 0;
}

耗时比较(单位:秒)

  O1 O2 O3(Ox) 优化集合(无快速浮点优化) 优化集合
VS2008 C/C++ Compiler 10.015 9.530 9.530 2.734 1.968
gcc4.4.4 10.250 10.250 10.265 7.203 5.328
Intel C/C++ Compiler 11.1 9.375 9.343 9.343 9.015 8.843

优化集合为

VS2008 C/C++ Compiler /Ox /Ob2 /Og /Oi /Ot /Oy /fp:fast /arch:SSE2
gcc4.4.4 -O3 -ftracer -fivopts -ftree-loop-linear -ftree-vectorize -fforce-addr -fomit-frame-pointer -fno-bounds-check -funroll-loops -ffast-math -march=native -mfpmath=sse -mmmx -msse -msse2 -msse3
Intel C/C++ Compiler 11.1 /fast /O3 /Ot /Og /Oi /Qipo /QxHost /arch:SSE3 /Qunroll /Qvec /Quse-intel-optimized-headers /Qparallel /fp:fast=2 /Ob2 /GT /GA

 

二、三角函数

main.c(来源于Intel官方)

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

#define INTEG_FUNC(x)  abs(sin(x))

int main(void)
{
   unsigned int i, j, N;
   double step, x_i, sum;
   double start, finish, duration;
   double interval_begin = 0.0;
   double interval_end = 2.0 * 3.141592653589793238;

   start = clock();

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

     N =  1 << j;
     step = (interval_end - interval_begin) / N;
     sum = INTEG_FUNC(interval_begin) * step / 2.0;

     for (i=1;i<N;i++)
     {
        x_i = i * step;
        sum += INTEG_FUNC(x_i) * step;
     }

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

耗时比较(单位:秒)

  O1 O2 O3(Ox) 优化集合(无快速浮点优化) 优化集合
VS2008 C/C++ Compiler 9.687 9.343 8.734 8.281 6.843
gcc4.4.4 20.219 20.296 20.593 15.062 15.046
Intel C/C++ Compiler 11.1 6.640 4.828 4.828 4.812 4.812

 

优化集合同上

相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载