Click here to Skip to main content
13,625,824 members
Click here to Skip to main content
Add your own
alternative version


4 bookmarked
Posted 12 Apr 2013
Licenced CPOL

C++ Include test: full matrix

, 17 Apr 2013
Rate this:
Please Sign up or sign in to vote.
Experiments about compilation times and file structure in C++, using GCC, MinGW, Visual Studio.
Finally I am able to present some include experiment results! Previously I wrote about Code Generator and now I can actually run this tool and get some numbers out of it. I compared VC11.0 (Visual Studio 2012 For Desktop) and GCC 4.7.2 (using MinGW32 4.7.2 and DevCpp).

Basics of experiment

  • VC11.0 - Visual Studio 2012 For Desktop, Release Mode, 32bit, no optimizations.
    • I turned build timings on to have detailed build performance.
  • GCC 4.7.2 32bit - MinGW 4.7.2 version and run from DevCpp 5.4.1
    • g++.exe -c testHeaders.cpp -o testHeaders.o -ftime-report
  • The machine: Core i5, 4 cores, 4GB RAM, Windows 8 64bit
    • compilation will probably take place only on one core only (there will be one translation unit only)
I run each test 3 times and then compute the average. At the end of post there is a link to detailed spreadsheet.

Code structure

The overall code structure is not a real case scenario. It was my first attempt to do such experiment and it was actually easy to create such hierarchy.

  • testHeader.cpp includes N header files
  • m-th header file includes N-1 other header files (so we have "cross" include)
  • each header file has its proper include guard
Note: For 199 GCC will return an error "#include nested too deeply". You can read more about it in In general GCC thinks that 199 include level is unreal and will block it.

Test N headers

A header can look like this in this tests:

    #include "header_0.h"
    #include "header_1.h"
    #include "header_2.h"
    #include "..."  
generator.exe N 100 includeTestOutput/
N = 100
GCC Compilation2,99s
VC11.0 Compilation2,68s
N = 132
GCC Compilation3,98s
VC11.0 Compilation4,11s
N = 164
GCC Compilation4,92s
VC11.0 Compilation5,91s
N = 192
GCC Compilation5,77s
VC11.0 Compilation7,77s

Test N headers - additional ifDef

A header can look like this in this tests:

        #include "header_0.h"
        #include "header_1.h"
        #include "header_2.h"
    #include "..." 
generator.exe N 100 includeTestOutput/ ifDef
N = 100
GCC Compilation2,96s
VC11.0 Compilation1,22s
N = 132
GCC Compilation3,91s
VC11.0 Compilation1,51s
N = 164
GCC Compilation4,86s
VC11.0 Compilation1,77s
N = 192
GCC Compilation5,69s
VC11.0 Compilation1,96s

Test N headers - #pragma once

A header can look like this in this tests:

#pragma once
    #include "header_0.h"
    #include "header_1.h"
    #include "header_2.h"
    #include "..." 
generator.exe N 100 includeTestOutput/ pragmaOnce
N = 100
GCC Compilation3,08s
VC11.0 Compilation1,28s
N = 132
GCC Compilation4,06s
VC11.0 Compilation1,65s
N = 164
GCC Compilation5,08s
VC11.0 Compilation1,86s
N = 192
GCC Compilation5,98s
VC11.0 Compilation2,20s


  • The code structure is rather theoretical and does not represent 'common' structures that may appear in projects.
  • GCC and VC build code a bit different. GCC linker phase is much longer than in VC.
  • GCC uses lots of optimization for header files. There is almost no need to do any 'tricks' with includes. Header guards are enough.
  • VC likes header files 'tricks'!
    • There is above 2X to 3X speedup using additional include guards or pragma once
    • Pragma once for such code structure seems to be a bit slower than additional include guards: from 5% to even 10% slower.
  • All in all VC11.0 is faster than GCC.

What I have learnt

  • VC Release mode is not the same as GCC basic compilation
  • Make sure you set up proper experiment base
  • Automate as much as possible
  • Tool for spreadsheet is a must have-software Smile | :)
  • It is valuable to figure out how to break the compiler


Article is posted also on the CodeProject


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Bartlomiej Filipek
Software Developer
Poland Poland
Software developer interested in creating great code and passionate about teaching.

I have around 10 years of professional experience in C++/Windows/Visual Studio programming. Plus other technologies like: OpenGL, game development, performance optimization.

If you like my articles please subscribe to my coding blog or just visit

You may also be interested in...


Comments and Discussions

GeneralMy vote of 4 Pin
Jayanta Chatterjee13-Apr-13 2:25
memberJayanta Chatterjee13-Apr-13 2:25 
GeneralRe: My vote of 4 Pin
Bartlomiej Filipek15-Apr-13 8:46
memberBartlomiej Filipek15-Apr-13 8:46 
GeneralRe: My vote of 4 Pin
Jayanta Chatterjee16-Apr-13 4:17
memberJayanta Chatterjee16-Apr-13 4:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web04-2016 | 2.8.180712.1 | Last Updated 17 Apr 2013
Article Copyright 2013 by Bartlomiej Filipek
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid