3

It seems that the compilers usually implement #include "path/file.h" by firstly searching a path relative to the currently processed source file folder.

So the question is: how does it influence in practice the compilation time when using #include with quotes versus triangular brackets?

The question is only for the case when the "path/to/file/filename.h" is a relative path to the currently processed header, because otherwise it would behave similar to #include <…>.

It seems that the correctly set #include "…" should be faster for your own files than #include <…> in a large project (500 files or more).

Edit: Other questions about difference between #include "…" and #include <…> don't seem address compile time. Also, the standard is vague but most compilers do use "…" to search in the current folder first.

Edit2 Reworded the title and the question. I'll accept the answer for any of these C++ compilers: Visual Studio, Intel, Clang, Gcc.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
0kcats
  • 672
  • 5
  • 16
  • The standard simply says that the double quoted form may look in some different places for headers before looking for them in the same places as the angle-bracketed form looks in. Otherwise, it is implementation defined where the headers are sought. The difference in speed is unlikely to be measurable — and for many purposes, the notations are equivalent. On the whole, it is better to use angle brackets for 'system defined' headers (e.g. C++ standard headers) and double quotes for 'user defined' headers, but it is mostly a nominal difference. – Jonathan Leffler Sep 13 '16 at 15:16
  • @Pierre: the other question discusses format of `#include` directives, but not the processing speed of the two forms. – Jonathan Leffler Sep 13 '16 at 15:20
  • Also, the question comes for a project that targets multiple platforms, and uses three different compilers - VS, clang, gcc. A coding standard requires use of triangular brackets for all includes (the "." must be among include folders). – 0kcats Sep 13 '16 at 15:26
  • 5
    Compilers tend to be configured to search through multiple directories to find a .h file when you use angle brackets. So technically it could be slower. The odds that it *measurably* slower is very remote, those directories get hot in the file system cache quickly. After which file searches progresses at memory bus speeds, considerably less than the blink of an eye. If this really matters then always take advantage of the compiler's pre-compiled header feature, you'll definitely notice that. – Hans Passant Sep 13 '16 at 15:55
  • The subprojects do use the precompiled headers and they do list most dependency #include's from other subprojects or stl. This certainly helps a lot. – 0kcats Sep 13 '16 at 16:02
  • For what it's worth, a coding standard that requires angle brackets for all includes is, formally, stupid. Angle brackets are for system headers; there is no requirement that that syntax support files **at all**. A header can be some internal binary data in the compiler. Not that anybody does that, but quoted names will always work, both for header **files** (yours and the system's) as well as system headers that aren't files. – Pete Becker Sep 13 '16 at 17:46
  • @Pete Becker Here is a link to one http://www.stroustrup.com/JSF-AV-rules.pdf – 0kcats Sep 13 '16 at 18:51
  • https://stackoverflow.com/questions/21593/what-is-the-difference-between-include-filename-and-include-filename – 0kcats Jun 02 '21 at 23:26

0 Answers0