Visual C++ compiler optimization
Right click your project, pick "Properties". Now make sure that your current configuration is "Release". In the left part of the window, you should see a tree view with different categories. Optimization options are split amongst the C/C++ and linker entries.
Also, keep in mind, that optimization means the resulting binary is optimized. NOT actually building the binary. The speed gain might be explained due to not having to add debug code etc. but in general, I'd more likely expect building a release version with optimizations to take longer than creating a debug build.
Gambit King
Updated on June 05, 2022Comments
-
Gambit King almost 2 years
I've recently migrated from Dev-c++ to Visual C++ 2010, and found it much better within all aspects but one. When I compile and execute the code in Dev-c++ with the
best-optimization
option toggled, the compile time is greatly reduced, almost by half (mingw32
), but I can't seem to find any optimization options in Visual C++ 2010. How can I tell the compiler to optimize the code?-
Cody Gray over 12 yearsSeeing a reduction in compile time when you enable optimizations is strange. I doubt you'll see that in Visual Studio. It's liable to take longer to build with optimizations enabled. But that's okay, because you don't do that nearly as often.
-
Mario over 12 yearsWell, I definitely could see this happen, when running on an older or slower disk. Sure, it's still not the behaviour you should expect.
-
Jesse Good over 12 yearsYour looking for /O2 compiler option for fastest code (default setting for release builds) or /Ox to to do full optimization. Those would be the equivalent to best optimization option in Dev-c++.
-
Cody Gray over 12 years@Jesse: Confusingly,
/Ox
is not a higher level of optimization than/O2
. This confused me as well, so I asked a question about it. It turns out that throwing the/O2
switch gets you everything you get with/Ox
and more, so you probably want to use/O2
all the time, which is conveniently the default. The only other option you might want to be concerned with is/O1
, which minimizes code size, a different optimization strategy than/O2
. -
Gambit King over 12 yearsOk in release mode it gives me the same time as in Dev-c++, but since the project is still incomplete i'd like to keep working in debug mode, so i just have to click on release mode and click build to update the release rite or is there a way to get i to run faster on debug mode itself ( when i click on optimize options it says it is incompatible with /ZI) ? Thanks guys
-
Jesse Good over 12 years@CodyGray: Interesting, thanks for the info. They really need to fire the person who came up with naming scheme "/Ox (Full Optimization)" :)
-
-
Cody Gray over 12 yearsYou shouldn't need to mess with any of those optimization options. Switching to "Release" mode automatically turns on the default optimization settings, which are more than good enough, especially for someone new to Visual Studio. The options can all be pretty confusing.
-
Gambit King over 12 yearsOk thanks a lot ( it works on release mode but the timing hasn't improved much), also in debug mode i've set the optimization to /ox but i need to disable the debugging feature, where do i do that ?
-
Mario over 12 yearsDebug information is put into the pdb file(s). In release mode there's no debug information in the actual binary (not 100% sure about debug mode).
-
Cody Gray over 12 yearsIt's a setting. You can change it. The default is to put things in the PDB files. Not something you need to worry about, though. Just don't ship the PDB files if you don't want the debugging information public.