A performance benchmark of which include guard method is faster. Test times the compilation of a main.cpp that includes 10000 files 3 times each.

The tested methods are:

  • #pragma once followed by #ifndef
  • #ifndef followed by #pragma once
  • Only #pragma once
  • Only #ifndef
  • External #ifndef

Sources for the test is at inc.tar.gz, but it’s just 5×10000 files.

The compilers are Microsoft Visual C++ 2010, GNU g++ 4.6.1, and LLVM clang++ 2.9.


Continue Reading »