-7

I am not too familiar with the C++ compilers, i have never designed one. But can someone tell me whether increasing the length of a function or comment name increases the time to process (compile) the code?

So if i wrote:

void func1(){
std::cout << "Func1" << endl;
};

vs

void function2(){
std::cout << "Function 2" << endl;
};
Max Vollmer
  • 8,412
  • 9
  • 28
  • 43
AskJheeze
  • 33
  • 3
  • 1
    you dont need to design a compiler to get some numbers on that, see eg here for gcc https://stackoverflow.com/questions/3025443/how-to-calculate-gcc-compilation-time/5987523 – 463035818_is_not_an_ai Oct 01 '19 at 11:38
  • 1
    *the time to process the code* at compile time or runtime? – Borgleader Oct 01 '19 at 11:38
  • At compile time – AskJheeze Oct 01 '19 at 11:39
  • 1
    or here: https://stackoverflow.com/questions/11338109/gcc-understand-where-compilation-time-is-taken – 463035818_is_not_an_ai Oct 01 '19 at 11:39
  • The day a coworker of mine makes unreasonably short function names, or removes comments, in the name of speeding up compilation... – Cory Kramer Oct 01 '19 at 11:39
  • 5
    Stop projecting. People voluntarily used their free time here to provide you with the resources needed to answer your question. – Max Vollmer Oct 01 '19 at 11:49
  • Max Vollmer, and that is a very one sided view. Answering questions help the the reinforcing of knowledge – AskJheeze Oct 01 '19 at 11:54
  • 4
    I dont get the point. Why did you start flaming? You will have a hard time to find an answer to "WHat is 24+12?" in a maths book, but you will find detailed explanation of `+` and natural numbers. Similarly you cannot expect to get numbers presented comparing `func1` to `function1` when all you need to add to existing answers is a tiny bit of effort – 463035818_is_not_an_ai Oct 01 '19 at 12:05
  • 5
    Please take some time to re-read the [Code of Conduct](https://stackoverflow.com/conduct). Your behavior here is not acceptable and very far from friendly or kind. – Max Vollmer Oct 01 '19 at 12:18

1 Answers1

4

In principle, parsing longer input must be slower than parsing shorter input (assuming the entire input has to be parsed, which is certainly true for compilation). So yes, increasing function name or comment length does increase the time it takes to process your source code. The real question is, by how much?

And the answer is: in practical scenarios, not in any measureable way. Comments are simply discarded. Identifiers are probably hashed. It would surprise me if changing identifier/comment/literal length in any practical project affected compilation times by more than 0.1%

On the other hand, it could easily reduce programmers' understanding of the code to a small fraction of what it would be otherwise, which will increase development times, maintenance costs, and probability of introducing bugs.

Angew is no longer proud of SO
  • 167,307
  • 17
  • 350
  • 455