does white space slow down processing

前端 未结 5 750
孤独总比滥情好
孤独总比滥情好 2020-12-07 04:06

I have huge amounts of data to analyze, I tend to leave space between words or variable names as I write my code, So the question is, incases where efficiency is the number

5条回答
  •  难免孤独
    2020-12-07 04:53

    YES

    But, No, not really:

    TL;DR It would probably take longer just to run your script to remove the whitespaces than the time it saved by removing them.

    @Josh O'Brien really hit the nail on the head. But I juts couldnt resist to benchmark

    As you can see, if you are dealing with an order of magnitude of 100 MILLION lines then you will see a miniscule hinderance. HOWEVER With that many lines, there would be a high likelihood of their being at least one (if not hundreds) of hotspots, where simply improving the code in one of these would give you much greater speed than greping out all the whitespace.

      library(microbenchmark)
    
      microbenchmark(LottaSpace = eval(LottaSpace), NoSpace = eval(NoSpace), NormalSpace = eval(NormalSpace), times=10e7)
    
      @ 100 times;  Unit: microseconds
               expr   min     lq median     uq    max
      1  LottaSpace 7.526 7.9185 8.1065 8.4655 54.850
      2 NormalSpace 7.504 7.9115 8.1465 8.5540 28.409
      3     NoSpace 7.544 7.8645 8.0565 8.3270 12.241
    
      @ 10,000 times;  Unit: microseconds    
               expr   min    lq median    uq      max
      1  LottaSpace 7.284 7.943  8.094 8.294 47888.24
      2 NormalSpace 7.182 7.925  8.078 8.276 46318.20
      3     NoSpace 7.246 7.921  8.073 8.271 48687.72
    

    WHERE:

      LottaSpace <- quote({
            a            <-            3
            b                  <-                  4   
            c         <-      5
            for   (i            in      1:7)
                  i         +            i
      })
    
    
      NoSpace <- quote({
      a<-3
      b<-4
      c<-5
      for(i in 1:7)
      i+i
      })
    
      NormalSpace <- quote({
       a <- 3
       b <- 4 
       c <- 5
       for (i in 1:7)
       i + i
      })
    

提交回复
热议问题