views:

172

answers:

5

Hi,

Suppose a have a fairly complex class I'm working on. Half the methods are done and tested, but I'm still devolping the other half. If I put the finished code in one cpp and the rest in another, will Visual Studio (or any other IDE for that matter) compile faster when I only change code that's in the "work-in-progress" cpp?

Thanks!

A: 

As long as the header file doesn't change (assuming both .cpp's include the same header) then only the changed .cpp files will be compiled.

This is true for most IDEs at the very least. I haven't had experience in directly invoking compilers like gcc so I can't comment on that.

Nick Bedford
+2  A: 

Yes, I believe Visual Studio compiles incrementally, so as long as you hit Build and not Rebuild All you should get faster compile times by splitting out.

However, you should really be splitting out because of code-factoring reasons i.e. each class should have a single purpose etc. etc... I'm sure you know.

photographique
A: 

The answer is probably yes because you'll probably be performing incremental builds (compiling only the .cpp that changes) and pre-compiled headers. If you are not using either of these features, then you'll get slower builds. I'm pretty sure that a default Visual Studio C++ projects uses both incremental builds and pre-compiled headers.

Phillip Ngan
A: 

Yes it will be faster.

But more importantly: Don't worry about this, if your class is so large that it's taking a lot of time on a modern processor it's god's way of saying your class needs to get refactored into smaller pieces.

Jon Clegg
+1  A: 

It really depends. For a very large project, link time can often be considerably more expensive than the time to compile a single file. In our codebase at work (a game based on the Unreal Engine) we actually found that making "bulk.cpp" files that include many other files (effectively fewer translation units) decreases the turn around time significantly.

Even though individual compile time for a small change was increased, overall compile time (full rebuild) and link time (which happens even for a small change) both decreased dramatically.

Adisak
this is called unity build
fa.
The Unreal Engine uses the terminology "Bulk Build" so that's very common terminology in the game industry but "Unity Build" is the same thing. I have also heard the term "Uber-Build" but not nearly as often.Besides the obvious decrease in overall preprocessor time, we see a significant decrease in Linker time (several minutes), especially in template-heavy code like the Unreal Engine.A side benefit of Bulk/Unity Builds is that your code may run faster (larger chunks of code allows the compiler to optimize better - especially for function inlining).
Adisak