Do comments affect compilation time?

I am an Android developer, and in my opinion the following question came: when I comment on the compilation, I want to say that if we add our useful comment to the code, can the compiler spend some time on part of the comment?

If not, will it not work out since how long is our comment?

+7
source share
3 answers

can the compiler spend some time on part of the comment?

Apart from the overhead of the IO to move the bytes corresponding to the comment (which should be negligible as long as it is not a comment of a few megabytes in length), there will be no significance that it was so. Most compilers do not even include comments in the AST, which means that comments completely disappeared after parsing.

Never decide to include a comment based on compilation time. Base your decision solely on whether the code makes it more readable or not.

Further reading:

+21
source

Yes, every comment you write will make the compilation slower, because the compiler needs to read more text. But: reading comments is very simple for the compiler, and it is quickly done, so you should not worry about it.

You can try it yourself. Create a program that generates simple source code with lots of comments.

int i = 0; ... i++; /* This is a comment, and maybe a very long one. */ ... 

Now you can experiment to make this (generated) comment very long, maybe even megabytes. Then measure the difference when compiling the code with small and large comments, and you will see that the speed is still acceptable.

+11
source

It takes time to read and analyze this block of comments, but this time you will not notice so briefly and in any case not a reason not to put (extended and useful) comments in your programs :-)

+10
source

All Articles