Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve test for Lists vs. environments, and $ vs. [[ #284

Open
MLopez-Ibanez opened this issue Mar 4, 2024 · 0 comments
Open

Improve test for Lists vs. environments, and $ vs. [[ #284

MLopez-Ibanez opened this issue Mar 4, 2024 · 0 comments

Comments

@MLopez-Ibanez
Copy link

The example here:

```{r}
lst <- list(x = 10)
env <- new.env()
env$x <- 10
mb_summary(microbenchmark(
lst = lst$x,
env = env$x,
lst[['x']],
env[['x']]
))
```

is too trivial to show the actual differences. A better example would be

lst <- as.list(sample(letters))
names(lst) <- unlist(lst)
env <- new.env()
for (x in lst) assign(x, x, envir=env)
mb_summary(microbenchmark(
  lst = lst$x,
  env = env$x,
  lst[['x']],
  env[['x']]
))

which gives in my computer:

         name median
1        lst 0.6345
2        env 0.2850
3 lst[["x"]] 0.4085
4 env[["x"]] 0.1960
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant