Skip to content
Prev 316002 / 398513 Next

Copy on assignment and .Internal(inspect())

Here's another approach using the sampling profiler:

prof <- function() {
  Rprof(memory.profiling=T, interval=0.001)
  replicate(100, f())
  Rprof(NULL)
  summaryRprof(memory = "stats")
}

f <- function() {
  x = seq(1000)
  for(i in seq(1000)) {
    x[i] <- x[i] + 1
  }
}

prof()

=>

index: "prof":"replicate"

     vsize.small  max.vsize.small      vsize.large  max.vsize.large
            1938           285003             1629           210990

           nodes        max.nodes     duplications tot.duplications
          265805         13949348                7             1703

         samples
             251

Average duplications are just 9 for 1000 executions of x[i] <- x[i] +
1. A lot of optimization seems to be going on!

How do I make sense of the output listed in my previous post, then?

Best regards
--
Carlos
On Thu, Jan 24, 2013 at 12:38 AM, Carlos Pita <carlosjosepita at gmail.com> wrote: