GCC Compiler Optimization

GCC Compiler Optimization

In the classroom, you have been using a compiler called GCC. You've been compiling code with the following command:

g++ -std=c++11 main.cpp blur.cpp initialize_beliefs.cpp move.cpp normalize.cpp print.cpp sense.cpp zeros.cpp

By default, gcc will try to lower the time it takes to compile your code; in other words, gcc optimizes for compilation time.

However, gcc can also optimize for execution time to get your code to run faster. The gcc compiler includes three levels of optimization, which you can use by adding the optimization flag to your compilation command: -O1 -O2 -O3

You can read more about what each level does at this link: Optimization Flags Link

Now that you have optimized your histogram filter code, go back and try compiling the program with the level three flag. See how much the compiler can help you speed up your code.

Here is the command for compiling with level three optimization:

g++ -std=c++11 -O3 main.cpp blur.cpp initialize_beliefs.cpp move.cpp normalize.cpp print.cpp sense.cpp zeros.cpp

Last updated