g++代码编译⽤选项-O3前后对⽐,前后执⾏时间对⽐如下g++代码编译⽤选项-O3前后对⽐,前后执⾏时间对⽐如下
g++ -std=c++11 main.cpp blur.cpp initialize_beliefs.cpp move.cpp normalize.cpp print.cpp n.cpp zeros.cpp
荆轲刺秦王失败的原因
root@b8da9efe81e4:/home/workspace/optimized_code# ./a.out
number of iterations: 10000
duration milliconds initialize beliefs 22.599
duration milliconds n 16.463
duration milliconds blur 77.062
duration milliconds normalize 20.721
duration milliconds move 31.484
/今早2.13⽤该条编译器优化看看是否较上条提升了性能
g++ -std=c++11 -O3 main.cpp blur.cpp initialize_beliefs.cpp move.cpp normalize.cpp print.cpp n.cpp zeros.cpp
//编译优化后的
root@65c825f71a98:/home/workspace/optimized_code# ./a.out
number of iterations: 10000
duration milliconds initialize beliefs 3.284
duration milliconds n 3.972
duration milliconds blur 26.045
duration milliconds normalize 2.177
duration milliconds move 4.634
Depending on the target and how GCC was configured, a slightly different t of optimizations may be enabled at each -
O level than tho listed here. You can invoke GCC with -Q --help=optimizers to find out the exact t of optimizations that are enabled at each level. See , for examples.鸡的功效与作用
-O
-O1
Optimize. Optimizing compilation takes somewhat more time, and a lot more memory for a large function.
With -O, the compiler tries to reduce code size and execution time, without performing any optimizations that take a great deal of compilation time.
-O turns on the following optimization flags:
-fauto-inc-dec
-fbranch-count-reg学习兴趣
-fcombine-stack-adjustments
-
fcompare-elim总务科科长
-fcprop-registers
-fdce
-fdefer-pop
-fdelayed-branch
-fd
-fforward-propagate
-fguess-branch-probability
-fif-conversion
-fif-conversion2
-finline-functions-called-once
-
fipa-profile
-fipa-pure-const
-fipa-reference
-fipa-reference-addressable
-fmerge-constants
-fmove-loop-invariants
-fomit-frame-pointer
-freorder-blocks
-fshrink-wrap
-fshrink-wrap-parate
-fsplit-wide-types
-
fssa-backprop
-fssa-phiopt
-ftree-bit-ccp
-ftree-ccp
-ftree-ch
-ftree-coalesce-vars
-ftree-copy-prop
-ftree-dce
-ftree-dominator-opts
-ftree-d
-ftree-forwprop
-
ftree-fre忌惮是什么意思
-ftree-phiprop
-ftree-pta
-ftree-scev-cprop
-ftree-sink
-ftree-slsr
-ftree-sra
-ftree-ter
-funit-at-a-time
-O2
Optimize even more. GCC performs nearly all supported optimizations that do not involve a space-s
peed tradeoff. As compared to -O, this option increas both compilation time and the performance of the generated code.
-O2 turns on all optimization flags specified by -O. It also turns on the following optimization flags:
-falign-functions -falign-jumps
-falign-labels -falign-loops
吃硬不吃软-fcaller-saves
-fcode-hoisting
-fcrossjumping
-fc-follow-jumps -fc-skip-blocks
-fdelete-null-pointer-checks
-fdevirtualize -fdevirtualize-speculatively
祝你生日快乐吉他谱
-fexpensive-optimizations
-ffinite-loops
-fgc -fgc-lm
-fhoist-adjacent-loads
-finline-functions
金刚殿-finline-small-functions
-findirect-inlining
-fipa-bit-cp -fipa-cp -fipa-icf
-fipa-ra -fipa-sra -fipa-vrp
-fisolate-erroneous-paths-dereference
-flra-remat
-foptimize-sibling-calls
-
foptimize-strlen
-fpartial-inlining
-fpeephole2
-freorder-blocks-algorithm=stc
-freorder-blocks-and-partition -freorder-functions
-frerun-c-after-loop
-fschedule-insns -fschedule-insns2
-fsched-interblock -fsched-spec
-fstore-merging
-fstrict-aliasing
-fthread-jumps
-
ftree-builtin-call-dce
-ftree-pre
-ftree-switch-conversion -ftree-tail-merge
-ftree-vrp
Plea note the warning under -fgc about invoking -O2 on programs that u computed gotos.
-O3
Optimize yet more. -O3 turns on all optimizations specified by -O2 and also turns on the following optimization flags:
-fgc-after-reload
-fipa-cp-clone
-floop-interchange
-floop-unroll-and-jam
-fpeel-loops
-fpredictive-commoning
-fsplit-paths
-ftree-loop-distribute-patterns
-ftree-loop-distribution
-ftree-loop-vectorize
-ftree-partial-pre
-ftree-slp-vectorize
-funswitch-loops
-fvect-cost-model
-fversion-loops-for-strides
-
O0
Reduce compilation time and make debugging produce the expected results. This is the default.
-Os
Optimize for size. -Os enables all -O2 optimizations except tho that often increa code size:
-falign-functions -falign-jumps
-falign-labels -falign-loops
-fprefetch-loop-arrays -freorder-blocks-algorithm=stc
It also enables -finline-functions, caus the compiler to tune for code size rather than execution speed, and performs further optimizations designed to reduce code size.