C++ – Is an 8 second (incremental) build time common

c

My current project takes 8 seconds to build one C++ file. Is this common? Other files take 12-15 seconds but most at the moment are about 8 seconds. I use Visual Studio to tell me the time.

I have gone into the headers and removed things I didn't need and used forward declaration. It did save me about 2 seconds per file and one header takes about 4 seconds to go through alone. In that header I need all its declarations and using a lite version which removes private methods public functions I don't need.

Should I be happy it's 8 or so seconds or is that too long to compile one file?

Best Answer

C++ is a very complicated language, and due to many factors the compiler needs several passes to determine what a certain symbol is. The result is that C++ programs are slower to compile than programs of comparable complexity written in other languages. Here is an insightful article that covers the subject (it was written by Walter Bright, the creator of D and the author of the Digital Mars C and C++ compilers). Considering this, your 8 seconds compilation seems reasonable.

Good practices to increase compilation speed:

  • forward declaration whenever possible
  • precompiled headers
  • #pragma once (not standard, but both MSVC and GCC support it)
  • pimpl pattern
Related Topic