LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
楼主: fallening

大家都用什么CFLAGS?

[复制链接]
发表于 2008-2-25 16:17:08 | 显示全部楼层
发重了,没有删除机制?
回复 支持 反对

使用道具 举报

发表于 2008-2-25 16:20:55 | 显示全部楼层
不过native的时候,编译的东西普遍要比非native的小一点,几K到几十K不等。
唉,还是不应该轻信什么“推荐”参数和“新特性”阿,早知道就自己测试一把了。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2008-2-25 20:20:21 | 显示全部楼层
Post by zhuqin_83;1819895
晕死,不过你这样测试岂不是没有比较。

我测了6组(所有数据都是测多次求均,cpu设为performance,即频率保持最大)
测试环境:arch linux 2.6.24.1,gcc 4.2.3,cpu=Dothan2 1.73GHz,RAM=1.5GB,纯console模式。
1。-O2 -march=pentium-m -pipe -fomit-frame-pointer====================>8.91"
2。-O2 -march=native -pipe -fomit-frame-pointer=======================>9.14"
3。-O2 -march=pentium-m -pipe -fomit-frame-pointer -msse2 -mmmx -mfpmath=sse=>8.91"
4。-O2 -march=native -pipe -fomit-frame-pointer -msse2 -mmmx -mfpmath=sse====>9.14"
5。-O3 -march=pentium-m -pipe -fomit-frame-pointer====================>8.91"
6。-O3 -march=native -pipe -fomit-frame-pointer=======================>9.14"

故结论是:
1。-march=pentium-m快于-march=native
2。-msse2 -mmmx之类不必另行添加,有-march就会自动加上相对应的。
3。-mfpmath看不出来作用。
4。-O2和-O3在这个测试中表现一致。其实据官方称,也就最多1%的区别,可能变慢,可能变快,后者体积会更大一些,不稳定一些,风险大。

所以,我们应该选择
-march=xxx(非native)-O2 -pipe -fomit-frame-pointer
绕了半天终于回来了,哭。。。



不过偶用的是笔记本,确实是Pentium M,用了-march=pentium-m参数,你的Dothan2 是不是该修改下这个参数
回复 支持 反对

使用道具 举报

发表于 2008-2-25 20:42:49 | 显示全部楼层
dothan是迅驰2,所以,没什么好改的。
Pentium M(Centrino)/Celeron M

vendor_id  : GenuineIntel
cpu family  : 6
model  : 9 or 13
model name  : Intel(R) Pentium(R) M processor XXXXMHz

For gcc 3.3 or older (Warning: dev-java/sun-jdk needs old libstdc++-3.3.so on X86 Systems) :

CHOST="i686-pc-linux-gnu"
CFLAGS="-march=pentium3 -msse2 -O2 -pipe -fomit-frame-pointer"
CXXFLAGS="${CFLAGS}"

For gcc 3.4 and later:

CHOST="i686-pc-linux-gnu"
CFLAGS="-march=pentium-m -O2 -pipe -fomit-frame-pointer"
CXXFLAGS="${CFLAGS}"

The Celeron M is based on the Pentium M but it has half the L2 cache and does not support the SpeedStep technology.
回复 支持 反对

使用道具 举报

发表于 2008-2-25 20:47:55 | 显示全部楼层
大家有不同cpu的话不妨验证一下,看看我的结论是否普适,以后也就不必再争论这个话题了。
也即所谓的safe cflags,同样也是suboptimization的,照wiki上做肯定没问题,性能也有保证。注意是gcc4.2以后的版本哦,pacman.conf会holdpkg gcc,故需要手动加上#。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2008-2-25 21:06:45 | 显示全部楼层
How about the compile time?
It seems to me native faster than pentium-m, and I shall test it soon after.
回复 支持 反对

使用道具 举报

发表于 2008-2-25 21:35:25 | 显示全部楼层
native生成的包要小一点点。编译时间这个小程序是看不出来的了,应该差不多,-O2和-O3的时间应该差的较多。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2008-2-25 22:47:28 | 显示全部楼层
I composed a simple program using cpp
  1. //compile_time_test.cc
  2. #include <iostream>
  3. #include <cstdlib>
  4. #include <ctime>
  5. #include <string>
  6. using namespace std;
  7. int main()
  8. {
  9.     clock_t start;
  10.     clock_t finish;
  11.     string compile_flag[6] = {
  12.                     "-O2 -march=pentium-m -pipe -fomit-frame-pointer",
  13.                     "-O2 -march=native -pipe -fomit-frame-pointer",
  14.                     "-O2 -march=pentium-m -pipe -fomit-frame-pointer -msse2 -mmmx -mfpmath=sse",
  15.                     "-O2 -march=native -pipe -fomit-frame-pointer -msse2 -mmmx -mfpmath=sse",
  16.                     "-O3 -march=pentium-m -pipe -fomit-frame-pointer",
  17.                     "-O3 -march=native -pipe -fomit-frame-pointer"
  18.     };
  19.     string command = "g++ -c compile_time_test.cc  ";
  20.     string cmd;
  21.     for ( unsigned int flg = 0; flg < 6; ++flg )
  22.     {
  23.         cmd = command + compile_flag[flg];
  24.         start = clock();
  25.         for ( unsigned int i = 0; i < 100; ++i )
  26.         {
  27.             system( cmd.c_str() );
  28.         }
  29.         finish = clock();
  30.         long double duration = static_cast<long double>
  31.             ( finish - start ) / CLOCKS_PER_SEC;
  32.         cout << "It costs "<< duration
  33.              << " second(s) to compile compile_time_test.cc 100 times using flag "
  34.              << compile_flag[flg] << ".\n";
  35.     }
  36.     return 0;
  37. }
复制代码

and the result
It costs 0 second(s) to compile compile_time_test.cc 100 times using flag -O2 -march=pentium-m -pipe -fomit-frame-pointer.
It costs 0.01 second(s) to compile compile_time_test.cc 100 times using flag -O2 -march=native -pipe -fomit-frame-pointer.
It costs 0 second(s) to compile compile_time_test.cc 100 times using flag -O2 -march=pentium-m -pipe -fomit-frame-pointer -msse2 -mmmx -mfpmath=sse.
It costs 0.01 second(s) to compile compile_time_test.cc 100 times using flag -O2 -march=native -pipe -fomit-frame-pointer -msse2 -mmmx -mfpmath=sse.
It costs 0.05 second(s) to compile compile_time_test.cc 100 times using flag -O3 -march=pentium-m -pipe -fomit-frame-pointer.
It costs 0.07 second(s) to compile compile_time_test.cc 100 times using flag -O3 -march=native -pipe -fomit-frame-pointer.
回复 支持 反对

使用道具 举报

发表于 2008-2-28 15:23:46 | 显示全部楼层
mine..


  1. [lh@Zero test]$ g++ -c ran.cc -Wall -O2 -march=k8 -pipe -fomit-frame-pointer -msse3
  2. [lh@Zero test]$ g++ -c test.cc -Wall -O2 -march=k8 -pipe -fomit-frame-pointer -msse3
  3. [lh@Zero test]$ g++ -o test -Wall -O2 -march=k8 -pipe -fomit-frame-pointer -msse3 test.o ran.o
  4. [lh@Zero test]$ ./test
  5. It costs 8.48 second(s) to generate 100000000 random numbers.
  6. 9.259
  7. Sum of them is 4.99981e+07


  8. [lh@Zero test]$ g++ -c ran.cc -O2 -march=k8 -pipe -fomit-frame-pointer -msse3
  9. [lh@Zero test]$ g++ -c test.cc -O2 -march=k8 -pipe -fomit-frame-pointer -msse3
  10. [lh@Zero test]$ g++ -o test -O2 -march=k8 -pipe -fomit-frame-pointer -msse3 test.o ran.o
  11. [lh@Zero test]$ ./test
  12. It costs 8.52 second(s) to generate 100000000 random numbers.
  13. 8.944
  14. Sum of them is 4.9996e+07

  15. [lh@Zero test]$ g++ -c ran.cc -O2 -march=k8 -mtune=generic -pipe -fomit-frame-pointer -msse3
  16. [lh@Zero test]$ g++ -c test.cc -O2 -march=k8 -mtune=generic -pipe -fomit-frame-pointer -msse3
  17. [lh@Zero test]$ g++ -o test -O2 -march=k8 -mtune=generic -pipe -fomit-frame-pointer -msse3 ran.o test.o
  18. [lh@Zero test]$ ./test
  19. It costs 10.05 second(s) to generate 100000000 random numbers.
  20. 9.79
  21. Sum of them is 5.00034e+07

  22. [lh@Zero test]$ g++ -c ran.cc -O2 -pipe -fomit-frame-pointer -msse3
  23. [lh@Zero test]$ g++ -c test.cc -O2 -pipe -fomit-frame-pointer -msse3
  24. [lh@Zero test]$ g++ -o test -O2 -pipe -fomit-frame-pointer -msse3 ran.o test.o[lh@Zero test]$ ./test
  25. 9.786
复制代码


i didnt test -O3 and -native ,the result is just what safe flag said....
回复 支持 反对

使用道具 举报

发表于 2008-4-25 08:10:38 | 显示全部楼层
无聊又做了一个测试,结果差点让我屁股亲密接触了地板。
gcc 4.3, 内核2.6.24。
1。-O2 -march=pentium-m -pipe -fomit-frame-pointer====================>9.5"
2。-O2 -march=native -pipe -fomit-frame-pointer=======================>8.8"
3。-march=i686 -mtune=generic -O2 -pipe==>9.26"
4。-O2 -march=native -pipe===========>9.35"

疯了。。。大家用native重新编译吧,肯定不吃亏。之前还说4.3有多少性能提升的,看来是不升反降。另外,-fomit-frame-pointer这个参数还是挺管用的。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表