Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2145
  • Last Modified:

G++ Compiler -O (Optimization) Tag

What's the benefeits of using this tag?

I'm compiling a MUD engine, right now using g++ -c, and am wondering if there's any benefeit (and if, then what specifically) -O optimization will give me, in terms of space, memory, speed, etc. And if I should use it.

Thanks!

Matt-
matt@anji.smhall.org
 
0
tribal9
Asked:
tribal9
1 Solution
 
sosedadaCommented:
-O is equivalent to -O1, or the first optimization level.  g++ also has -O2, -O3, and -Os.  The downside of these is compilation time.  However, they will speed up your program, definitely.  I believe in most cases executable size is decreased, but this is not guaranteed.

-O1, -O2, -O3 perform increasing amounts of optimization, require increasing amounts of time and also have a higher chance of breaking.  Optimization usually only breaks if your code is really complex.  

-Os is an options that performs no optimizations that increase executable size.  This means less speed optimization but a greater decrease in size.

As far as memory usage goes, optimization should decrease it.  Variables may be eliminated and optimization should decrease the number of lines of code necessary.

I would recommend using -O1 (or -O) for sure.  Perhaps before distribution, you could play with the higher optimization options to see how they would benefit you.
0
 
jkrCommented:
sosedada - wow, great elaboration! (indeed  - hard to improve...  ;-)
0
 
tribal9Author Commented:
By far the best answer I have recieved on here in awhile.

You earned your 5 points. =)


0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now