The Optimizer, Makefiles, Separate Compilation, #Include in C++

Channel:
Subscribers:
2,640
Published on ● Video Link: https://www.youtube.com/watch?v=9b8__aO37e4



Duration: 1:11:54
117 views
2


Today we learned a number of really crucial concepts in computer science, especially in regards to the ELO assignment, as they're used there.

1) The Optimizer is turned all the way on with the -O3 compile flag. So you'd type "g++ -O3 main.cc" to compile main.cc with the optimizer all the way on. We did some benchmarking and found pretty substantial performance gains with the ELO assignment, and also showed how it could be used to sometimes eliminate entire loops or function calls for massive speed boosts.

2) We introduced the concept of Makefiles, which look a bit weird at first, but basically are instructions on how to build your project intelligently. This is most useful when you have a lot of files in your directory and building them all by hand would be annoying. You type "make" to build your project and then it does all the rest. Sometimes you need to "make clean" to reset the project back to a pre-build state when you do things like turn on the address sanitizer.

3) Separate Compilation goes hand in hand with Makefiles, with the ability to split declarations into header files (.h files) and the actual code in implementation files (.cc or .cpp or .C or .cxx files). This allows you to speed up your build time so you don't need to do a full recompile in the project.

4) We talked about what #include does - it just copy/pastes whatever file you include into your document. For something like hello world, it increases the size of your code by about 10,000 times. Don't include what you don't need!







Tags:
csci 40
optimizer
optimizing compiler
makefile
separate compilation
#include
c++