Solved

G++ Compiler -O (Optimization) Tag

Posted on 1998-12-29
3
2,137 Views
Last Modified: 2012-05-12
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
Comment
Question by:tribal9
3 Comments
 
LVL 1

Accepted Solution

by:
sosedada earned 0 total points
ID: 1181272
-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
 
LVL 86

Expert Comment

by:jkr
ID: 1181273
sosedada - wow, great elaboration! (indeed  - hard to improve...  ;-)
0
 

Author Comment

by:tribal9
ID: 1181274
By far the best answer I have recieved on here in awhile.

You earned your 5 points. =)


0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question