Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do comments slow down R?

Tags:

r

Do comments slow down R?

This question has been asked twice on StackOverflow regarding python:

Do comments slow down an interpreted language? Will excessive commenting of code slow execution?

For python the answer appears to be 'no'. I do not know enough about the differences between the two languages to know how relevant those answers are for R.

Here is a similar question about white space in R. Again the answer appears to be 'no'.

does white space slow down processing

like image 330
Mark Miller Avatar asked Apr 09 '14 19:04

Mark Miller


People also ask

Do comments make program slower?

Commenting will not affect the script execution time in normal case. But the number of lines you write in your code affect the parser to read and buffer it considerably.

Do comments affect performance?

No it does not effect performance. As most of the programming languages compile or interpret code and comments are skipped as computer has nothing to do with comments.

Do comments affect runtime?

Since comments have no impact on the runtime results, they are sometimes neglected when the source code is updated. Source code maintenance as a result of a production bug is often done under time pressure and maintaining comments is seen as an unnecessary delay.

Do comments affect file size?

So just wanted to know whether keeping that code inside my java file affect the size of the compiled class file? No, Commented code is not part of class file. But, if you are using version-control system, you should remove the comments also to enhance readability and maintainability.


1 Answers

For R the answer appears to be 'yes', unless I made a mistake somewhere below.

# Time difference of 21.84725 secs
# Time difference of 24.05738 secs

# total.time.2 - total.time.1
#
# Time difference of 2.210126 secs

n <- 280

start.time.1 <- Sys.time()

b <- 2

for(i in 1:n) {
     for(j in 1:n) {
          for(k in 1:n) {

               b <- b + 2 - 1 - 0.75

          }
     }
}

b

end.time.1 <- Sys.time()

total.time.1 <- end.time.1 - start.time.1
total.time.1


start.time.2 <- Sys.time()

b <- 2

# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.


for(i in 1:n) {

# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.

     for(j in 1:n) {

# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.

          for(k in 1:n) {

# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.

               b <- b + 2 - 1 - 0.75

# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.
# I wonder whether comments slow down R.  Here are some comments.  Let's see.

          }
     }
}

b

end.time.2 <- Sys.time()

total.time.2 <- end.time.2 - start.time.2

total.time.1
total.time.2

total.time.2 - total.time.1
like image 83
Mark Miller Avatar answered Oct 30 '22 00:10

Mark Miller