What is the difference between the /Ox and /O2 compiler options?

前端 未结 2 785
野的像风
野的像风 2020-11-30 02:33

Microsoft\'s C++ compiler (cl.exe, as included with Visual Studio) offers several optimization switches. The difference between most of them seems self-explanat

相关标签:
2条回答
  • 2020-11-30 02:38

    Asha's answer cites a blog post about Visual Studio 2005, and is rather out of date.

    The latest version of the documentation is available here:

    • /Ox: https://msdn.microsoft.com/en-us/library/59a3b321.aspx
    • /O2: https://msdn.microsoft.com/en-us/library/8f8h5cxt.aspx

    According to those:

    • /Ox/Og /Oi /Ot /Oy /Ob2
    • /O2 → the same, but further adds /Gs /GF /Gy

      • /GF eliminates duplicate strings
      • /Gy does function level linking

    You may additionally be interested in /GS- which turns off security checks around the stack, which can be a significant performance hit (see the MS docs for /GS).

    You should benchmark your specific application, as ever.

    0 讨论(0)
  • 2020-11-30 03:00

    I found it here:

    Ox and O2 are almost identical. They differ only in the fact that O2 also throws GF and Gy. There is almost no reason to avoid throwing these two switches.

    0 讨论(0)
提交回复
热议问题