Thread: Compile time

  1. #1
    Registered User
    Join Date
    Mar 2010

    Compile time

    Supposing I have multiple very long (large number of code lines) cpp file (one major including the others, which, it turn, include some), and given that (for a specific purpose) I would need only a small portions of the files (functions spread over multiple files), I wonder what would be the way to decrease the amount of time needed for compiling process.

    Would compile time decrease if I just comment the unnecesarry code from each file? Or, is it better to extract the necessary part and to compile it separately? How would these two approaches differ?

    Also, the header file inclusion might affect the compilation time, I guess (major cpp file includes other .cpp files, not a .h convention). So, is packing everything in one file more efficient in terms of compilation time? Perhaps including .h files is more efficient than including .cpp files?

  2. #2
    Join Date
    Oct 2007
    Inside my computer
    Never include .cpp files.
    Splitting up your code into multiple files is always the fastest method.
    Commenting out code will almost be equally fast. There will probably be no or insignificant difference.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Registered User
    Join Date
    May 2010
    First you should rarely if ever include a .cpp file. A .cpp file should be added to your IDE or makefile to be compiled, not included. To decrease build time of your project you can create a library to hold the functions that are fairly static (completed, bug tested, not changing) and then add that library to your build process. Then the required functions would linked to your program without the need to compile them.


  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    This has also been answered elsewhere.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    And yet more selfish cross-posting (and time wasting!)
    Compile time - Dev Shed
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #6
    Registered User
    Join Date
    Mar 2010
    Thanks for your answers. I understand your point, but please note that I do not have any inappropriate intentions. Given the time constraint, it was urgent to get proposals, which usually are different. So, in a sense, you could put everything as "selfish" (there are pages on this, not mine), but, again, I'll try to follow the rules every next time.
    I hope you understand.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Grouping Question
    By baikal_m in forum C Programming
    Replies: 7
    Last Post: 10-26-2010, 04:41 PM
  2. compile time error
    By kapil1089thekin in forum C++ Programming
    Replies: 4
    Last Post: 09-01-2010, 12:29 PM
  3. Length of string at compile time?
    By TriKri in forum C Programming
    Replies: 14
    Last Post: 05-23-2010, 11:16 AM
  4. NtSetSystemTime() failed
    By medp7060 in forum C++ Programming
    Replies: 11
    Last Post: 04-02-2010, 02:58 AM
  5. time class
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 12-11-2001, 10:12 PM