Compile time

This is a discussion on Compile time within the C++ Programming forums, part of the General Programming Boards category; Supposing I have multiple very long (large number of code lines) cpp file (one major including the others, which, it ...

  1. #1
    Registered User
    Join Date
    Mar 2010
    Posts
    43

    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?
    Thanks

  2. #2
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,413
    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
    Posts
    2,684
    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.

    Jim

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,313
    This has also been answered elsewhere.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,422
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  6. #6
    Registered User
    Join Date
    Mar 2010
    Posts
    43
    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, 09:12 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21