how about performance of the program compiled by -O2 other than -Os?

Brian Dessent
Fri Jun 13 09:37:00 GMT 2008

PRC wrote:

> How about performance of the program compiled by -O2 other than -Os?
> I think -O2 will be better than -Os? But I am not sure how better.

It's impossible to answer such a vague question, as it depends on the
target architecture, the version of gcc, and most significantly the
nature of the code.  You can only answer these kinds of questions with a
testcase, but I would not rule out -Os being faster in some
circumstances and on some architectures due to more code fitting in the
cache or better locality.

> BTW, how about -Os vs -O0?

-O0 means perform no optimization at all and I don't see how it's
meaningful to compare optimized to unoptimized code in either size or
speed.  -O0 is useful when you want short compile times or you need to
be able to debug the resulting code easily, but other than that don't
expect much.  But again, it entirely depends on the details and it's
really hard to conclude anything without a testcase.


More information about the Gcc-help mailing list