Everyone knows C++ includes are expensive, but how expensive are they? I tested it in Windows 10 on a 2.53Ghz machine using Visual Studio’s CL.exe (msbuild 14.0) and clang 7.0.1. The test was done with the source code and includes on a regular hard drive, not an SSD. A comparison of SSD versus HDD will be done later.

The test was performed by compiling the source code below 128 times, calculating the average time.

int test_function() { return 0; } 1 int test_function ( ) { return 0 ; }

Each include was then individually added and the compilation was run another 128 times with this command line for cl.exe:

cl.exe /nologo /EHsc /I"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include" /I"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\atlmfc\include" /I"C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt" /I"C:\Program Files (x86)\Windows Kits\8.1\Include\um" /I"C:\Program Files (x86)\Windows Kits\8.1\Include\shared" /I"C:\Program Files (x86)\Windows Kits\8.1\Include\winrt" /c __test_source.cpp > __test_buildoutput.txt 1 cl . exe / nologo / EHsc / I "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include" / I "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\atlmfc\include" / I "C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt" / I "C:\Program Files (x86)\Windows Kits\8.1\Include\um" / I "C:\Program Files (x86)\Windows Kits\8.1\Include\shared" / I "C:\Program Files (x86)\Windows Kits\8.1\Include\winrt" / c __test_source . cpp > __test_buildoutput . txt

and this command line for clang:

"C:\Program Files\LLVM\bin\clang.exe" -I"C:\Program Files\LLVM\lib\clang\7.0.1\include" -std=c++17 -c __test_source.cpp > __test_buildoutput.txt 1 "C:\Program Files\LLVM\bin\clang.exe" - I "C:\Program Files\LLVM\lib\clang\7.0.1\include" - std = c ++ 17 - c __test_source . cpp > __test_buildoutput . txt

C headers were gathered from: https://en.cppreference.com/w/c/header while C++ headers came from: https://en.cppreference.com/w/cpp/header.

The average of the base time was then subtracted, giving these compilation times, in seconds.

header cl.exe clang.exe algorithm 0.192 0.327 any 0.027 0.332 array 0.362 0.547 assert.h 0.01 0.007 atomic 0.353 0.702 bit 0.019 ¯\_(ツ)_/¯ bitset 0.356 0.601 cassert 0.014 0.005 cctype 0.018 0.01 cerrno 0.016 0.008 cfenv 0.012 0.018 cfloat 0.014 0.006 charconv 0.024 ¯\_(ツ)_/¯ chrono 0.174 0.312 cinttypes 0.016 0.017 climits 0.011 0.004 clocale 0.011 0.007 cmath 0.044 0.07 codecvt 0.368 0.628 compare 0.02 ¯\_(ツ)_/¯ complex 0.39 0.608 concepts 0.023 ¯\_(ツ)_/¯ condition_variable 0.308 0.595 contract 0.023 ¯\_(ツ)_/¯ csetjmp 0.011 0.009 csignal 0.016 0.005 cstdarg 0.011 0.005 cstddef 0.011 0.011 cstdint 0.017 0.005 cstdio 0.048 0.068 cstdlib 0.019 0.056 cstring 0.024 0.024 ctime 0.014 0.012 ctype.h 0.01 0.01 cuchar 0.017 0.005 cwchar 0.061 0.078 cwctype 0.018 0.009 deque 0.232 0.368 errno.h 0.015 0.009 exception 0.076 0.1 execution 0.019 ¯\_(ツ)_/¯ experimental/algorithm 0 ¯\_(ツ)_/¯ experimental/algorithm 0 ¯\_(ツ)_/¯ experimental/algorithm 0 ¯\_(ツ)_/¯ experimental/any 0 ¯\_(ツ)_/¯ experimental/array 0 ¯\_(ツ)_/¯ experimental/atomic 0 ¯\_(ツ)_/¯ experimental/barrier 0 ¯\_(ツ)_/¯ experimental/chrono 0 ¯\_(ツ)_/¯ experimental/deque 0.213 ¯\_(ツ)_/¯ experimental/deque 0.209 ¯\_(ツ)_/¯ experimental/exception_list 0 ¯\_(ツ)_/¯ experimental/execution_policy 0 ¯\_(ツ)_/¯ experimental/filesystem 0.612 ¯\_(ツ)_/¯ experimental/forward_list 0.206 ¯\_(ツ)_/¯ experimental/forward_list 0.2 ¯\_(ツ)_/¯ experimental/functional 0 ¯\_(ツ)_/¯ experimental/functional 0 ¯\_(ツ)_/¯ experimental/future 0 ¯\_(ツ)_/¯ experimental/future 0 ¯\_(ツ)_/¯ experimental/iterator 0 ¯\_(ツ)_/¯ experimental/latch 0 ¯\_(ツ)_/¯ experimental/list 0.203 ¯\_(ツ)_/¯ experimental/list 0.202 ¯\_(ツ)_/¯ experimental/map 0.225 ¯\_(ツ)_/¯ experimental/map 0.221 ¯\_(ツ)_/¯ experimental/memory 0 ¯\_(ツ)_/¯ experimental/memory 0 ¯\_(ツ)_/¯ experimental/memory_resource 0 ¯\_(ツ)_/¯ experimental/numeric 0 ¯\_(ツ)_/¯ experimental/numeric 0 ¯\_(ツ)_/¯ experimental/optional 0 ¯\_(ツ)_/¯ experimental/propagate_const 0 ¯\_(ツ)_/¯ experimental/random 0 ¯\_(ツ)_/¯ experimental/ranges/algorithm 0 ¯\_(ツ)_/¯ experimental/ranges/concepts 0 ¯\_(ツ)_/¯ experimental/ranges/functional 0 ¯\_(ツ)_/¯ experimental/ranges/iterator 0 ¯\_(ツ)_/¯ experimental/ranges/random 0 ¯\_(ツ)_/¯ experimental/ranges/range 0 ¯\_(ツ)_/¯ experimental/ranges/tuple 0 ¯\_(ツ)_/¯ experimental/ranges/type_traits 0 ¯\_(ツ)_/¯ experimental/ranges/utility 0 ¯\_(ツ)_/¯ experimental/ratio 0 ¯\_(ツ)_/¯ experimental/regex 0 ¯\_(ツ)_/¯ experimental/set 0.211 ¯\_(ツ)_/¯ experimental/set 0.21 ¯\_(ツ)_/¯ experimental/source_location 0 ¯\_(ツ)_/¯ experimental/string 0.366 ¯\_(ツ)_/¯ experimental/string 0.365 ¯\_(ツ)_/¯ experimental/string_view 0 ¯\_(ツ)_/¯ experimental/system_error 0 ¯\_(ツ)_/¯ experimental/tuple 0 ¯\_(ツ)_/¯ experimental/type_traits 0 ¯\_(ツ)_/¯ experimental/type_traits 0 ¯\_(ツ)_/¯ experimental/unordered_map 0.234 ¯\_(ツ)_/¯ experimental/unordered_map 0.231 ¯\_(ツ)_/¯ experimental/unordered_set 0.223 ¯\_(ツ)_/¯ experimental/unordered_set 0.221 ¯\_(ツ)_/¯ experimental/utility 0 ¯\_(ツ)_/¯ experimental/vector 0.211 ¯\_(ツ)_/¯ experimental/vector 0.208 ¯\_(ツ)_/¯ fenv.h 0.008 0.009 filesystem 0.594 0.92 float.h 0.01 0.006 forward_list 0.232 0.365 fstream 0.294 0.537 functional 0.206 0.48 future 1.12 1.57 initializer_list 0.013 0.009 inttypes.h 0.01 0.008 iomanip 0.298 0.535 ios 0.288 0.537 iosfwd 0.096 0.178 iostream 0.291 0.541 istream 0.298 0.538 iterator 0.302 0.507 limits 0.11 0.163 limits.h 0 0.004 list 0.223 0.368 locale 0.371 0.641 locale.h 0.015 0.01 map 0.243 0.393 math.h 0.021 0.022 memory 0.196 0.337 memory_resource 0.019 ¯\_(ツ)_/¯ mutex 0.303 0.59 new 0.063 0.101 numeric 0.128 0.272 optional 0.02 0.333 ostream 0.288 0.533 queue 0.223 0.403 random 0.343 0.641 ranges 0.02 ¯\_(ツ)_/¯ ratio 0.046 0.105 regex 0.426 0.698 scoped_allocator 0.201 0.337 set 0.229 0.369 setjmp.h 0.004 0.007 shared_mutex 0.312 0.602 signal.h 0.008 0.005 span 0.02 ¯\_(ツ)_/¯ sstream 0.36 0.582 stack 0.207 0.37 stdarg.h 0.004 0 stddef.h 0.013 0 stdexcept 0.226 0.359 stdint.h 0.003 0.004 stdio.h 0.046 0.068 stdlib.h 0.018 0.032 streambuf 0.285 0.501 string 0.4 0.567 string_view 0.026 0.502 string.h 0.017 0.026 strstream 0.311 0.545 syncstream 0.017 ¯\_(ツ)_/¯ system_error 0.263 0.409 thread 0.254 0.539 time.h 0.013 0.016 tuple 0.144 0.276 type_traits 0.046 0.096 typeindex 0.065 0.114 typeinfo 0.062 0.114 uchar.h 0.01 0.007 unordered_map 0.235 0.418 unordered_set 0.234 0.396 utility 0.12 0.217 valarray 0.2 0.331 variant 0.021 0.385 vector 0.228 0.374 version 0.022 ¯\_(ツ)_/¯ wchar.h 0.048 0.078 wctype.h 0.01 0.008

The top 5 header times for cl.exe:

future 1.12 experimental/filesystem 0.612 filesystem 0.594 regex 0.426 string 0.4

The top 5 header times for clang.exe:

future 1.57 filesystem 0.92 atomic 0.702 regex 0.698 locale 0.641

edit: added clang info, reorganized tables, added some specifics on testing