Created
October 18, 2011 02:28
-
-
Save markmfredrickson/1294468 to your computer and use it in GitHub Desktop.
Comparing the size of expand.grid with a list of functions of the same size.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gsize <- function(n) { | |
grid <- expand.grid(rep(list(1:10), n)) | |
object.size(grid) / 1024 | |
} | |
fsize <- function(n) { | |
f <- function(i) {force(i) ; function(j) { i + j}} | |
flst <- lapply(1:(10^n), f) | |
object.size(flst) / 1024 | |
} | |
# a function to compare object sizes | |
comparison <- function(n) { | |
fsize(n) - gsize(n) | |
} | |
# > sapply(1:5, comparison) | |
# [1] 3.796875 47.585938 486.140625 4841.140625 48043.718750 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment