[Rd] Understanding tracemem
Hadley Wickham
hadley at rice.edu
Thu Jul 12 19:49:50 CEST 2012
> The list gets copied, but do a and b, or does the new list point to
> the existing locations? The following test suggests that it's a deep
> copy.
>
> x <- 1:1e7
> z <- list(a = x)
>
> system.time(replicate(100, z$b <- 1L)) / 100
> # ~ 0.05s
> system.time(replicate(100, x[1e6 + 1L] <- 1L)) / 100
> # ~ 0.04s
But that should be
system.time(replicate(100, x[1e7 + 1L] <- 1L)) / 100
# ~0.10s
system.time(replicate(100, z$b <- 1L)) / 100
# ~ 0.04s
which suggests that it's not a deep copy.
But
x <- 1:1e6
z <- list(a = x)
system.time(replicate(100, z$b <- 1L)) / 100
# ~0.005s
which suggests it's not a shallow copy either.
But then neither of those are probably good tests because they modify
in place. I'll think more.
Hadley
--
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/
More information about the R-devel
mailing list