2016-04-20 15 views
-4

私は最近、クラスでパフォーマンスラボを完成しましたが、私のバディーが私になぜ私がなぜその理由を理解できないかを示す1つのことがありました。これがメイクファイルに変更されてパフォーマンスが向上するのはなぜですか?

## 
## 

CXX =g++ 
CXXFLAGS= -m32 -static 

をしかし、私はにCXXFLAGSを変更: は元のmakefileで、私たちは持っていた-funroll-ループはオリジナルにはないことを、正確に何をし-O3ん

## 
## 

CXX =g++ 
CXXFLAGS= -m32 -static -funroll-loops -O3 

+6

'-O3'は、最適化の束を可能にします。 '-funroll-loops'は最適化です。一緒に、彼らは最適化と複数の最適化をオンにします。それが最適化のポイントであるため、プログラムが最適化されたときにプログラムはより速くなりました。 – Ryan

+4

コンパイラのドキュメントを参照してください。 'man gcc'とオプションを探します。 –

答えて

3

お試しください: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. 

それが役に立てば幸い!