我最近在类里面完成了一个性能实验室,但我的 friend 向我展示了一件事,我不明白为什么。 在原始的 makefile 中,我们有:
##
##
CXX =g++
CXXFLAGS= -m32 -static
但我将 CXXFLAGS 更改为:
##
##
CXX =g++
CXXFLAGS= -m32 -static -funroll-loops -O3
-funroll-loops -O3 到底做了什么而原始版本没有做的事情?
最佳答案
试试这个:man gcc
!
-funroll-loops
:
-funroll-loops Unroll loops whose number of iterations can be determined at compile time or upon entry to the loop. -funroll-loops implies -frerun-cse-after-loop, -fweb and -frename-registers. It also turns on complete loop peeling (i.e. complete removal of loops with a small constant number of iterations). This option makes code larger, and may or may not make it run faster.
-O1
:
-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.
-O2
-O2 Optimize even more. GCC performs nearly all supported optimizations that do not involve a space-speed tradeoff. As compared to -O, this option increases both compilation time and the performance of the generated code.
-O3
-O3 Optimize yet more.
-O0
-O0 Reduce compilation time and make debugging produce the expected results. This is the default.
-0s
-Os Optimize for size. -Os enables all -O2 optimizations that do not typically increase code size. It also performs further optimizations designed to reduce code size.
-Ofast
-Ofast Disregard strict standards compliance. -Ofast enables all -O3 optimizations. It also enables optimizations that are not valid for all standard-compliant programs. It turns on -ffast-math and the Fortran-specific -fno-protect-parens and -fstack-arrays.
希望有帮助!
关于c - 为什么对 makefile 的更改会使性能提高?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36731682/