Compilation Modes

It has been proven to be a good practice to develop, test, and debug code in what is called Debug mode. In this mode, all compilation optimizations are disabled and all symbol and other debug information is being generated by the compiler. This is necessary to enable the use of the debugger (the symbol information is required to access source line and variable name information during debugging) and to avoid code restructuring by the compiler (disable optimizations).

Debug mode is the default mode of the build system if you configure your project using CMake for the first time. You can see the current mode of you build system by expanding the Project Status in the CMake pane of your VSCode environment:

Project Status Pane

After finishing with debugging, especially when measuring performance characteristics of your code, you should switch your build system to Release mode by clicking on the ‘pen’ right next to the Debug text. This will open a selection on the top of VSCode:

Select Build Mode

where you can select Release Optimize for Speed. Switching back to Debug mode is similar.

It is very important to perform timing measurements in Release mode as this will usually give you a significant performance gain compare to Debug mode.

After selecting a new build mode for your build system you will have to rebuild your project.