gcccompilation

Estimating compile time?


Is there any rule of thumb for determining a 'reasonable' amount of compilation time for a program? Obviously it's somewhat subjective what 'reasonable' means, but all things being equal, a console-based "Hello, World" shouldn't take 2 hours to compile, for instance. To provide a concrete example --

Given a repository of C-code, X # of lines of code, gcc optimization level Y, ... is there any reasonable way to predict the amount of time for compilation? And any opinions on what's a 'reasonable' amount of time?

Clarification

The parameters of interest here are only code dependent, NOT CPU, memory, network dependent.


Solution

  • For most reasonable programs built from reasonable sources on reasonable development machines (2+GHz, 4+GiB RAM), then answer for compiling a single source file should be 'a few seconds'. Anything in the minutes range usually indicates a problem, in my experience. The time taken to compile a complete program is then controlled by how many files there are to compile; it takes longer to compile 20,000 files than it does to compile 20 — roughly a thousand times as long, in fact. (Reasonable sources usually have source files under 10k lines and headers under about 1k lines — there are plenty of exceptions to either guideline, and both numbers are fairly generous.)

    But it all depends. If your headers are on a network file system, compilation is likely to be slower than if they are on local file system — unless your local drive is slow, the network blazingly fast and backed by SSD, and ... oh, gosh; there are just so many factors that it is nigh-on impossible to give a good answer!