1

Possible Duplicate:
What strategies have you used to improve build times on large projects?

I have some 800 lines of coding done in C++, the cpp file has some 7-8 classes with equal no objects as well, but the program takes good 7 seconds to build. This is my first program in c++, so I want to know if its normal? or its way too much? Also, it would be really great if someone who's expert in c++ could share some insights which would help a beginner as me. If it helps in any way I am using Visual Studio 2010.

Community
  • 1
  • 1
vin
  • 869
  • 4
  • 17
  • 33
  • It might be because of header only libraries (like boost::asio). In that case you should use precompiled headers. – Mohammad Jun 20 '12 at 16:37
  • What's the problem? When you have 8000 lines of code, does it take 7.5 seconds to build? – Bo Persson Jun 20 '12 at 16:40
  • Yes, what you're experiencing is normal. – i_am_jorf Jun 20 '12 at 16:42
  • 7.5 seconds is hardly anything to worry about. I have worked on many systems which took 20-40 **minutes** to compile and link. – wallyk Jun 20 '12 at 16:42
  • @vin - Yes, I know it's 800. But what if you have 8000 or 80000 - does it take any longer? – Bo Persson Jun 20 '12 at 16:47
  • @vin: The reason BoPersson is asking is that there may be, say, a fixed overhead of 6.5 seconds, plus 1 second per 8000 lines to compile the code, If so, VS2010 is probably fast enough for most reasonable projects, just not great for very short toy projects. That would be very different than if it took, e.g., 1 second per 90 lines, which would be unreasonably slow for almost any project. – abarnert Jun 20 '12 at 18:44
  • I used to have to build Windows. It regularly took an hour to just build the shell project. A full installable CD image took >24hrs. So, we all had a good chuckle at the 7.5 seconds thing. More specifics about what the actual concern here would be useful for the OP to add. – i_am_jorf Jun 20 '12 at 21:31

2 Answers2

3

The time to compile C++ probably varies more than with any other language I've ever used.

One thing that can make a significant difference is what headers you're including. Even though your code may only be 800 lines, if a few of those are #includes, the compiler may easily be looking at thousands of lines (just for reference, #include <windows.h>, by itself, generally means the compiler will look at over 10,000 lines).

A few of us in the C++ chat room were recently doing some tests on a particularly nasty piece of code that has a lot of recursive templates. Even though it's only about 30 lines of code, depending on the parameters you set, it's pretty easy to get compiles times of an hour or more -- and with most compilers (including VC++10 and 11/2012) it's pretty easy to outright crash the compiler.

If the code has little or nothing in the way of headers and/or templates (especially things like recursive templates), then 7.5 seconds to compile seems fairly excessive. Just for comparison, I did a quick test compiling a program I had lying around that's close to the same size (926 lines). That took 0.3 seconds. My machine is something like 5 or 6 years old, so its speed isn't even close to cutting edge either. At the same time, I should add that for compiling that small an amount of code, CPU speed probably isn't the main determining factor. I'd expect an SSD to make a lot more difference than a faster CPU.

Jerry Coffin
  • 476,176
  • 80
  • 629
  • 1,111
0

C++ is a complicated language that requires more time to compile than many other languages. On top of that Visual Studio itself has additional overhead for building Intellisense databases and such. There's also a linking phase to consider after the actual compilation.

When Visual Studio creates a new project, it typically creates a precompiled header that includes a lot of Windows header files. This would add many thousands of lines to your 800-line source.

7 seconds seems a little slow, but not out of line.

Mark Ransom
  • 299,747
  • 42
  • 398
  • 622