2

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!

Pedro d'Aquino
  • 5,130
  • 6
  • 36
  • 46
  • I think, you have to read this thread - http://stackoverflow.com/questions/364240/how-do-you-reduce-compile-time-and-linking-time-for-visual-c-projects-native – KV Prajapati Oct 01 '09 at 01:28
  • As the other posters pointed out, it will probably compile faster, but i doubt that you'll notice the difference. But why don't you just try it (that should be quickly done) and report your experiences here :-) ... – MartinStettner Oct 01 '09 at 01:44

5 Answers5

2

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.

1

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
  • 6,708
  • 38
  • 46
  • 1
    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 Oct 01 '09 at 15:52
0

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
  • 4,365
  • 30
  • 36
0

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
  • 15,482
  • 8
  • 63
  • 79
0

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
  • 3,870
  • 4
  • 25
  • 22