【发布时间】:2016-02-23 07:31:33
【问题描述】:
这里我编译了一个 -O2 优化级别的输入程序(使用 gcc 4.8.4)并测量执行时间:
gcc -O2 -c test.c -o obj.o
TIMEFORMAT='%3R' && time(./obj.o)
execution time = 1.825
当我用 -O2 https://gcc.gnu.org/onlinedocs/gcc-4.8.4/gcc/Optimize-Options.html#Optimize-Options 级别的 GCC 手册中定义的选项列表替换 -O2 标志时:
gcc -fauto-inc-dec -fcompare-elim -fcprop-registers -fdce -fdefer-pop -fdse -fguess-branch-probability -fif-conversion2 -fif-conversion -fipa-pure-const -fipa-profile -fipa-reference -fmerge-constants -fsplit-wide-types -ftree-bit-ccp -ftree-builtin-call-dce -ftree-ccp -ftree-ch -ftree-copyrename -ftree-dce -ftree-dominator-opts -ftree-dse -ftree-forwprop -ftree-fre -ftree-phiprop -ftree-slsr -ftree-sra -ftree-pta -ftree-ter -funit-at-a-time -fthread-jumps -falign-functions -falign-jumps -falign-loops -falign-labels -fcaller-saves -fcrossjumping -fcse-follow-jumps -fcse-skip-blocks -fdelete-null-pointer-checks -fdevirtualize -fexpensive-optimizations -fgcse -fgcse-lm -fhoist-adjacent-loads -finline-small-functions -findirect-inlining -fipa-sra -foptimize-sibling-calls -fpartial-inlining -fpeephole2 -fregmove -freorder-blocks -freorder-functions -frerun-cse-after-loop -fsched-interblock -fsched-spec -fschedule-insns -fschedule-insns2 -fstrict-aliasing -fstrict-overflow -ftree-switch-conversion -ftree-tail-merge -ftree-pre -ftree-vrp -c test.c -o obj.o
TIMEFORMAT='%3R' && time(./obj.o)
execution time = 2.652
我的问题是为什么执行时间不同,我应用了相同的优化?
更新
如果(根据 GCC 文档):
并非所有优化都直接由标志控制。
那么研究人员如何使用比标准优化序列更快的方法来重现优化序列(使用进化算法,他们 用于生成数千个优化序列并收集这些 对执行时间的影响最大)
例如“Acovea”http://hg.ahs3.net/acovea/debian/html/acoveaga.html
【问题讨论】:
-
可能有更令人满意的解释,但在抢占式多任务系统(例如,所有桌面、移动和服务器)上,总是有可能发生其他事情。通常,人们倾向于运行许多计时测试并将它们平均以获得更有用的数字,这些数字不受备份软件的支配:)。
-
文档上写着
Depending on the target and how GCC was configured, a slightly different set of optimizations may be enabled at each -O level than those listed here. You can invoke GCC with -Q --help=optimizers to find out the exact set of optimizations that are enabled at each level....你试过-Q --help=optimizers -
@user2357112 -fdelayed-branch 用于 Fortran。我不需要它。我只删除了这个选项
-
@staticx:Fortran?我认为分支延迟没有任何特定于语言的内容。当然,特定于架构 - 我不认为延迟分支在 x86 上是一个问题 - 但它可能无论如何都会影响某些东西。
-
由于代码相同,您的问题似乎毫无意义。你的测量方法显然是错误的。提供minimal reproducible example
标签: c performance gcc compiler-optimization execution-time