I'd like to know which settings should I set so I can get my C++ programs code to be as optimized as possible for speed or size. How can I do that?
Thanks
I'd like to know which settings should I set so I can get my C++ programs code to be as optimized as possible for speed or size. How can I do that?
Thanks
You can use following switches of compilation to produce code optimized for speed.
You can find reference of compiler switches for code optimization here.
For the most part, I would say you don't need to worry too much about the switches. The defaults tend to be okay for most purposes. Mahin has pointed out where you can find what all the switches do, but you must be careful because they can have some unintended side-effects.
For example, the gcc compiler (which I am more familiar with) has a switch -fomit-frame-pointer. It is okay to use it. Doing so will free up a register. However, if your program crashes, you will get no stack traces. So, if you are trying to debug your program, you don't want this one. Other optimizations could have "crazier" side-effects depending on your system.
The other thing to point out is that, while the flags generally do what they say they are going to, it's not always guaranteed. For example, (again, in gcc), the /O3 flag should produce "more optimized" code. This isn't always the case however, and it's recommended to stick with /O2.