/Os, /Ot (Favor Small Code, Favor Fast Code)
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer

/Os, /Ot (Favor Small Code, Favor Fast Code)

/Os
/Ot

/Os (Favor Small Code) minimizes the size of executable files and DLLs by instructing the compiler to favor size over speed. The compiler can reduce many C and C++ constructs to functionally similar sequences of machine code. Occasionally these differences offer tradeoffs of size versus speed. The /Os and /Ot options allow you to specify a preference for one over the other:

/Ot (Favor Fast Code) maximizes the speed of .exe files and DLLs by instructing the compiler to favor speed over size. (This is the default.) The compiler can reduce many C and C++ constructs to functionally similar sequences of machine code. Occasionally these differences offer tradeoffs of size versus speed. The /Ot option is implied by the Maximize Speed (/O2) option. The /O2 option combines several options to produce very fast code.

Note   If you use /Os or /Ot you must also specify /Og in order to optimize the code.

x86 Specific>

The following example code demonstrates the difference between the Favor Small Code (/Os) options and the Favor Fast Code (/Ot) option:

Note   The following describes the expected behavior when using /Os or /Ot. However, compiler behavior from release to release may result in different optimizations for the code below.
/* differ.c
  This program implements a multiplication operator
  Compile with /Os to implement multiply explicitly as multiply.
  Compile with /Ot to implement as a series of shift and LEA instructions.
*/
int differ(int x)
{
    return x * 71;
}

As shown in the fragment of machine code below, when DIFFER.c is compiled for size (/Os), the compiler implements the multiply expression in the return statement explicitly as a multiply to produce a short but slower sequence of code:

   mov    eax, DWORD PTR _x$[ebp]
   imul   eax, 71                  ; 00000047H

Alternatively, when DIFFER.c is compiled for speed (/Ot), the compiler implements the multiply expression in the return statement as a series of shift and LEA instructions to produce a fast but longer sequence of code:

   mov    eax, DWORD PTR _x$[ebp]
   mov    ecx, eax
   shl    eax, 3
   lea    eax, DWORD PTR [eax+eax*8]
   sub    eax, ecx

END x86 Specific

To set this compiler option in the Visual Studio development environment

  1. Open the project's Property Pages dialog box. For details, see Setting Visual C++ Project Properties.
  2. Click the C/C++ folder.
  3. Click the Optimization property page.
  4. Modify the Favor Size or Speed property.

To set this compiler option programmatically

See FavorSizeOrSpeed Property.

See Also

/O Options (Optimize Code) | Compiler Options | Setting Compiler Options

Show:
© 2016 Microsoft