How expensive it is for the compiler to process an include-guarded header?

后端 未结 3 1071
后悔当初
后悔当初 2021-01-16 23:01

To speed up the compilation of a large source file does it make more sense to prune back the sheer number of headers used in a translation unit, or does the cost of compilin

3条回答
  •  猫巷女王i
    2021-01-16 23:56

    Assuming C/C++, simple recompilation of header files scales non-linearly for a large system (hundreds of files), so if compilation performance is an issue, it is very likely down to that. At least unless you are trying to compile a million line source file on a 1980s era PC...

    Pre-compiled headers are available for most compilers, but generally take specific configuration and management to work on non system-headers, which not every project does.

    See for example:

    http://www.cygnus-software.com/papers/precompiledheaders.html

    'Build time on my project is now 15% of what it was before!'

    Beyond that, you need to look at the techniques in:

    http://www.amazon.com/exec/obidos/ASIN/0201633620/qid%3D990165010/002-0139320-7720029

    Or split the system into multiple parts with clean, non-header-based interfaces between them, say .NET components.

提交回复
热议问题