When do spaces affect performance?

This is what I always thought about, so here it goes.

When I wrote the code, I was taught to highlight lines, comment on them, etc., to improve readability (I believe most of us). Obviously, I don’t see any problem in this, but it seemed to me that if all these whitespace and commented sections are ignored by the compiler / interpreter or something else, how much does this affect its performance?

Admittedly, I don’t know much about how the compiler works - only basic concepts. Nevertheless, I have a fair idea that in order to be able to "ignore spaces", you will first need to identify it (at least), and this will take work and, therefore, time.

So then I thought: what about spaces or comments at extreme levels? Say, millions or billions of their sections?

I assume that the question I ask is this: at what point (i.e., the extreme level) are sections of the code ignored that affect the ability of the compiler / interpreter to promptly output the result and, therefore, affect the user's work?

Thank.

+5
source share
7 answers

Try the following:

Can comments affect Perl performance?

Change comment.

A simple example using the hi world in a Scheme with different numbers of comments:

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# 

, 1GB , , , 512M RAM .

, /. , . , .

+3

, . , , , .

+4

( ) - 1.

- 2.

1 O ( ), , 1 ( ) . 10 ^ 4 , , , . 10 ^ 12 , , - .

2. 2, .

+1

, - , . , , , , - .

, , , , . . , , !

+1

.

, , , , .

, , .

- JavaScript, , , . - minifier, , .

, , , " ", /​​, , , , .

+1

Spaces in the source files have zero effect on the user interface. Once the binary is compiled, this. It doesn't matter if the compiler took delta-t longer to parse the source code, because there were millions of comments.

0
source

White space affects performance when white space is compiled into machine instructions. Fortunately, most normal languages ​​do not.

0
source

All Articles