Do Empty spaces/text slow down code?

  • Thread starter Thread starter Jarfi
  • Start date Start date
  • Tags Tags
    Code Empty
AI Thread Summary
Running a for-loop with 5000 cycles is generally not slowed down by two empty spaces or three comments in the code. The execution methods are either compile and run, where code is converted to machine code for optimal speed (common in languages like C/C++ and Fortran), or interpretive, where each line is processed sequentially. In the latter case, if spaces are included within quotes for printing, there could be a slight slowdown, but overall, spaces and comments are disregarded during execution. Thus, they do not significantly impact performance as the code is transformed into a more efficient executable format.
Jarfi
Messages
384
Reaction score
12
If you are say running a for-loop with 5000 cycles, will 2 empty spaces and say 3-comments slow this operation down?
 
Technology news on Phys.org
In general, no.

There are two methods of execution compile and run where code is converted to machine code and then run. This is the fastest option used for C/C++, Fortran...

The second method is interpretive where each line is tokenized and the tokens are processed and run:

http://en.wikipedia.org/wiki/Interpreter_(computing)

If your spaces were within quotes and were being printed each time then that would slow things down very very slightly. The more data you process the longer it takes a program to run.

However, in interpretive or compiled languages the spaces are removed from consideration as the code is converted to a more executable format.
 
  • Like
Likes elusiveshame
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I had a Microsoft Technical interview this past Friday, the question I was asked was this : How do you find the middle value for a dataset that is too big to fit in RAM? I was not able to figure this out during the interview, but I have been look in this all weekend and I read something online that said it can be done at O(N) using something called the counting sort histogram algorithm ( I did not learn that in my advanced data structures and algorithms class). I have watched some youtube...
Back
Top