4

This question and MSDN seem to imply that /O2 would be faster, but if you look at Microsoft's own SafeInt class, you will notice it says:

1) Compile optimized code - /Ox is best, /O2 also performs well. Interestingly, /O1 (optimize for size) does not work as well.

If the difference is truly just /GF /Gy as the question above says, then /GF is irrelevant (string pooling), and /Gy (omitting frame pointers) can't really hurt you, as far as I imagine.

Is there something I'm missing? Is /Ox faster in general? Why or why not?

Community
  • 1
  • 1
user541686
  • 205,094
  • 128
  • 528
  • 886
  • Sounds like the person who wrote that comment was also confused by the name of the respective options. They assumed, as I did, that `/Ox` was a higher level of optimization because the docs call it "full optimization". – Cody Gray - on strike Aug 11 '12 at 06:50
  • @CodyGray: I get the impression that they actually *tried* it, though... it didn't sound like speculation. – user541686 Aug 11 '12 at 06:58
  • They probably did. And they couldn't tell any difference between `/Ox` and `/O2`, they just chose to encourage the use of `/Ox` because it *sounded* better. They did say that `/O2` "also performs well". – Cody Gray - on strike Aug 11 '12 at 07:13
  • @CodyGray: I'm not seeing where you get that impression, since they said, clearly, `/Ox` *is* better... but if you really don't think they compared them then ok. – user541686 Aug 11 '12 at 07:21
  • Always profile, and on multiple CPUs. x86 is a complex family, and it's not always clear which compiler flags will generate the best results - it depends on a mix of you source code and target CPU. – snemarch Aug 12 '12 at 02:40

1 Answers1

1

/Gy is not frame pointer omission, that's /Oy, which is enabled under at least /Ox, /O1, /O2.

/Gy is COMDAT generation (function-level linking), which tends to reduce working set size, but shouldn't really affect code quality. And on template and inline code, such as SafeInt has, there's probably no discernable difference at all.

The MSDN page you linked also says to use /O2 instead of /Ox, so I don't think the idea that "/Ox faster in general" has any merit.

Ben Voigt
  • 277,958
  • 43
  • 419
  • 720
  • Oh whoops, my bad, COMDAT generation. But no, it's **not** "my idea" -- that's what the code comments say. Download `SafeInt3.hpp` and take a look for yourself; they clearly say `/Ox` is faster there. I'm confused as to why, or if that's general or not (again, if not, why). – user541686 Aug 11 '12 at 06:02
  • 1
    @Mehrdad: Sorry. I only was attributing the generalization to you, not the claim with respect to that particular file. Anyway, if you read the wording of the comment again, it's completely consistent with `/Ox` and `/O2` are equal and better than any other set of options. It's not the wording I would choose, but it is correct in that case to say `/Ox is best`. It just happens that `/O2` also is best. – Ben Voigt Aug 12 '12 at 02:20