This is something I've always wondered about, so here goes.
When writing code, I was/am taught to space out lines, comment them, etc... to improve the readibility (as I guess most of us are). I obviously don't see this as any kind of problem, but it got me thinking, if all of this whitespace and commented sections are being ignored by the compiler/interpreter or whatever else, how much does this impact on the its performance?
Admittedly, I don't know a lot about how a compiler operates - only the basic concepts. However, I have a fair idea that for one to be able to "ignore whitespace", it would first need to identify it (at least), and that takes work, and therefore time.
So then I thought, what about whitespace or comments at extreme levels? Say, millions or billions of sections of them?
I guess the question I'm asking is: At what point (ie. extreme level) will ignored sections of code impact a compiler's/interpreter's ability to produce a timely result and therefore impact on a user's experience?
Thanks.
No. We call that "whitespace" and in most (but not all) languages it is ignored. No matter what, no form of punctuation effects the execution speed of your code.
Show activity on this post. In a word, no!
White space, also known as “negative space,” is empty space around the content and functional elements of a page. The basic role of white space is to let your design breathe by reducing the amount of text and functional elements that users see at once.
No, Whitespaces (blank space) in your code are ignored by the compiler, which just skips over them while compiling the code. This also applies to comments. Spaces will only effect the size of your source code.
Try this:
Do comments affect Perl performance?
Edit for comment.
Simple example using a hello world in Scheme with varying zillions of comment lines:
netbsd1# ls -l file*
-rw-r--r-- 1 root wheel 1061 Mar 11 00:01 file.out
-rw-r--r-- 1 root wheel 102041 Mar 11 00:01 file1.out
-rw-r--r-- 1 root wheel 10200041 Mar 11 00:01 file2.out
-rw-r--r-- 1 root wheel 1020000041 Mar 11 00:03 file3.out
netbsd1# for i in file*
> do
> echo $i
> time ./scm $i
> done
file.out
hello world
0.06s real 0.01s user 0.01s system
file1.out
hello world
0.03s real 0.01s user 0.02s system
file2.out
hello world
0.64s real 0.28s user 0.30s system
file3.out
hello world
61.36s real 11.78s user 41.10s system
netbsd1#
Clearly, the 1GB file had major impact which is not necessarily surprising considering I only have 512M of RAM on this box.
Also, this is interpreting/compile speed. If you actually compiled these files, the runtimes would all be identical. You can draw your own conclusions defining impact.
It will not affect the compiled data as the word implies. However please dont go for comment diarrhea, it will affect other programmers performance.
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