Solved

G++ Compiler -O (Optimization) Tag

Posted on 1998-12-29
3
2,130 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
Comment Utility
-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
Comment Utility
sosedada - wow, great elaboration! (indeed  - hard to improve...  ;-)
0
 

Author Comment

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

You earned your 5 points. =)


0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
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.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

744 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

10 Experts available now in Live!

Get 1:1 Help Now