2016-04-20 10 views
-4

Ich habe vor kurzem ein Leistungslabor in der Klasse abgeschlossen, aber es gab eine Sache, die mein Kumpel mir zeigte, dass ich nicht herausfinden kann warum. Im ursprünglichen Make-Datei wir hatten:Warum ändert sich das Makefile, um die Leistung zu erhöhen?

## 
## 

CXX =g++ 
CXXFLAGS= -m32 -static 

Aber ich änderte den CXXFLAGS auf:

## 
## 

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

Was genau macht die -funroll-Schleifen-O3 tun, dass das Original nicht?

+6

'-O3' ermöglicht eine Reihe von Optimierungen. '-Funroll-Loops' ist eine Optimierung. Zusammen schalten sie eine Reihe von Optimierungen plus eins ein. Ihr Programm wurde schneller, wenn es optimiert wurde, denn das ist der Punkt der Optimierungen. – Ryan

+4

Sie sollten eindeutig die Dokumentation für Ihren Compiler konsultieren. 'man gcc' und suche nach den Optionen. –

Antwort

3

Versuchen Sie dies: 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. 

hoffe, es hilft!

Verwandte Themen