I was wondering whether declaring multiple things of the same type affects the compile time, such as below.
void a(),
b(),
c();
vs
void a();
void b();
void c();
I would be surprised if it didn't matter at all since the compiler will execute different code for the two cases, but it's impossible to guess which one would be faster, and whether one would be consistently faster than the other.
I would also be surprised if it were possible to measure the difference in any meaningful way, as it would most likely never be a question of more than a few microseconds.
If you're having problems with compilation time, declaration style is not the cause.
This answer discusses why the proposed code makes little difference to the compile time, which none of the other answers currently address.
Typically, some of the basic structure of a modern compiler is:
The part that analyzes the syntactic structure does something like this: When it recognizes a()
inside a declaration such as void a()
, it calls a routine elsewhere in the compiler that registers a
as an identifier with type function returning void
. This happens when a()
is recognized, when b()
is recognized, and when c()
is recognized.
The important thing in this case is that the same thing happens with both proposed code sequences: a()
, b()
and c()
are all recognized, and the same sequence of routine calls is made to register those identifiers. From then on, the processing of them is identical. In typical compilers, there will be no difference in the way a()
, b()
, and c()
are treated.
This means the only difference in the compiler’s processing of these code sequences is in the lexical analyzer and in the syntax processor. For one of the code sequences, there are a few more characters and a few more tokens, so that code sequence is likely to take slightly longer to process. However, with the speed of today’s computers, that amount of time is minuscule.
It is possible that slight differences in the processing can have cascading effects, if they happen to affect what is stored in processor cache or what memory is allocated and freed. However, these are completely incidental, the same way that, if a mechanic works on one car and happens to move their wrench to a different shelf while doing it, it can affect how long it takes them to work on the next car because they have to walk over to the shelf to get the wrench. It is just happenstance and not a meaningful cause-and-effect.
Not appreciably. Don't worry about it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With