【问题标题】:Do comments slow down R?评论会减慢 R 的速度吗?
【发布时间】:2014-05-23 04:57:17
【问题描述】:

cmets 减速了吗R

这个问题已经在 StackOverflow 上被问过两次关于 python 的问题:

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

对于python,答案似乎是否定的。我对这两种语言之间的差异了解不多,无法知道这些答案与R 的相关性。

这是关于R 中空白的类似问题。答案似乎又是“不”。

does white space slow down processing

【问题讨论】:

    标签: r


    【解决方案1】:

    对于 R,答案似乎是“是”,除非我在下面某处犯了错误。

    # 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
    

    【讨论】:

    • 是的,确实,例如在创建包时,R 会删除所有 cmets。这就是为什么我从未在 R 中看到有一行注释的函数(例如,给ls 提示) .
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-03
    • 1970-01-01
    • 2011-04-21
    相关资源
    最近更新 更多