Skip to content

Instantly share code, notes, and snippets.

@hadley
Created April 22, 2013 13:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hadley/5434786 to your computer and use it in GitHub Desktop.
Save hadley/5434786 to your computer and use it in GitHub Desktop.
library(microbenchmark)
options(digits = 2)
env <- environment(plot)
names <- ls(env)
microbenchmark(
as.list(env),
mget(names, env),
mget(ls(env), env))
# Unit: microseconds
# expr min lq median uq max neval
# as.list(env) 47 50 52 53 94 100
# mget(names, env) 35 37 38 39 54 100
# mget(ls(env), env) 365 367 368 379 498 100
env <- new.env()
env$x <- 1:10
env$y <- 1:100
microbenchmark(
as.list(env),
mget(c("x", "y"), env),
mget(ls(env), env))
# Unit: microseconds
# expr min lq median uq max neval
# as.list(env) 3.9 4.2 4.7 5.3 21 100
# mget(c("x", "y"), env) 1.9 2.3 2.5 2.7 22 100
# mget(ls(env), env) 11.8 12.6 13.1 13.6 42 100
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment