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?

- 10,381
- 13
- 48
- 86

- 483
- 3
- 8
- 18
-
Seeing 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. – Cody Gray - on strike Jan 13 '12 at 13:55
-
Well, I definitely could see this happen, when running on an older or slower disk. Sure, it's still not the behaviour you should expect. – Mario Jan 13 '12 at 13:58
-
1Your looking for [/O2 compiler option](http://msdn.microsoft.com/en-us/library/8f8h5cxt.aspx) 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++. – Jesse Good Jan 13 '12 at 13:58
-
@Jesse: Confusingly, `/Ox` is *not* a higher level of optimization than `/O2`. This confused me as well, so [I asked a question about it](http://stackoverflow.com/questions/5063334/what-is-the-difference-between-the-ox-and-o2-compiler-options). 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`. – Cody Gray - on strike Jan 13 '12 at 14:14
-
Ok 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 – Gambit King Jan 13 '12 at 14:21
-
1@CodyGray: Interesting, thanks for the info. They really need to fire the person who came up with naming scheme "/Ox (*Full* Optimization)" :) – Jesse Good Jan 13 '12 at 14:22
2 Answers
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.

- 35,726
- 5
- 62
- 78
-
1You 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. – Cody Gray - on strike Jan 13 '12 at 13:56
-
Ok 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 ? – Gambit King Jan 13 '12 at 14:03
-
Debug 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). – Mario Jan 13 '12 at 14:48
-
It'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. – Cody Gray - on strike Jan 14 '12 at 11:02
I only have VS C++ Express, but it should be the same in the full version...
In the "Project" menu select " Properties". This will open a dialog with all project settings. Look around at the different options available and you will soon find where to change optimization.
Also remember that when building in release mode, some optimizations are alredy turned on.

- 400,186
- 35
- 402
- 621