Programming‎ > ‎Language‎ > ‎C++‎ > ‎

Build Time


Compiling a C++ project can take a very long time. Here are ways to get the time down so it does not take forever to work on the project.

Language techniques
Header files
For each file compiled it needs to load all the headers, preprocess them and then compile them. Each header can includes other headers that include more headers and in the end it compiles huge amount of codes. It can be a huge waste of time as much of it is thrown away in the if you only use a few functions from the header.

Forward Declarations
Use Forward Declarations to avoid having to include whole header files when you only need a few of it's identifiers. If you use a pointer to MyStruct you do not need to include MyStruct.h if you use a forward declaration. In the CPP files that use MyStruct you need to include the complete header. For I/O streams include the <iosfwd.h> in the header and <iostream> in the implementation file.

Guard Conditions

Templates




Compiler options
Precompiled Headers

Use Parallelism
Use multi core compilation if your compiler support it.

Optimization Level
Using a lower optimization level when developing can speed up the compile time.



Faster Computer
The easy way out is to get a faster computer with SSD drive, more RAM and more CPU cores.




Comments