Skip to content
Back to formatted view

Raw Message

Message-ID: <CABdHhvETccpo28Oa1Bab0gpMQA_QJKTfvbe6jiHFh4TDdJY4Zg@mail.gmail.com>
Date: 2012-07-12T17:49:50Z
From: Hadley Wickham
Subject: Understanding tracemem
In-Reply-To: <CABdHhvHnS1zxORys7s2v1TB45qUjhkHxHqJ5COvRvGG+enyLkw@mail.gmail.com>

> 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/