gcc optimization parameters introduced (-O1, -O2, -O3, -Os)

-O set a total of five kinds of common

  1. O0: zero, indicating that close all optimization options, that is, the default parameters are not optimized
  2. Parameters -O1, -O2, -O3, as the numbers increased, the higher the degree of optimization of the code, but this is, in a sense, also to be debugging of programs at the expense of sacrificing.
  3. Os: -O2 is based on removing the final executable program that will lead to increased optimization, if you want a smaller executable program, you can use this option.

Several supplements

  1. Og is based on O1, which removed the effects of debugging optimized, so our goal is to debug a program, you can use this parameter. But just to have this argument is not enough, but this parameter tells the compiler that compiled code do not affect debugging, but debugging information generated by -g or parameters.
  2. -Ofast O3 is based on the addition of some unconventional optimizations that do not comply with international standards.
    You can use gcc -Q - help = optimizers command to query
    Here Insert Picture Description

After optimization of file size

Here Insert Picture Description

Published 52 original articles · won praise 26 · views 3390

Guess you like

Origin blog.csdn.net/weixin_43796685/article/details/104830756