#gcc笔记01 #gcc Compilation Options-o0-o1-o2-o3

Source: Internet
Author: User

-o0

-o1

-o2

-o3

4 levels of compiler optimization options,-o0 means no optimizations,-o1 defaults,-O3 optimization level most (here is Capital letter O)


Optimization Options (Source: http://blog.csdn.net/Sodier/article/details/452566)

This part of the content can be divided into two parts, part of this is to have the compiler analyze the code, and the other part is that we can make some information about the hardware for the compiler, and let him generate better code for the hardware, and we have to compile the program with the source code, in many cases, is for this reason.

First look at code optimization, from the overall optimization of code, GCC provides the following options

-o–o1

The two options have the same meaning, GCC will perform optimizations that reduce code size and execution time, and this level of optimization will not be performed for optimization options that can severely impact compilation time.

-o2

At this level GCC will provide all of the supported optimizations, but this does not include a space-time optimization, such as a compiler that does not use loop expansion and function inline. This option further speeds up the performance of compilation time and code generation compared to-O.

-o3

In addition to the optimization options provided by-o2, the-finline-functions,-funswitch-loops and-fgcse-afer-reload options are specified, with the goal of only one effort to perform code optimization.

-os

This option is specifically designed to optimize code size, and-os opens an optimization option that does not significantly increase code size in all-O2 levels

-o0

This option represents not performing optimizations

The point here is that although GCC provides the 4 overall optimization options for 1~3 and S, but from the actual optimization effect, often O3 optimization of the program is not the highest efficiency, and most of the cases we are using-O2, if you want to achieve the highest efficiency benefits, then may wish to try these 4 options. In addition, these options are simply a combination of many of the unilateral optimizations provided by GCC, and if you want to know more about the specifics of the optimization, you can go to the GCC Manual for space limitations. The last thing to keep in mind is that if your program is for high-precision numerical calculations, then remember not to use any of the optimization options above.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.