Solved

G++ Compiler -O (Optimization) Tag

Posted on 1998-12-29
3
2,132 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

911 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now