Last active
December 29, 2016 07:56
-
-
Save talegari/ad06da7795b8771e2e152f304ca00f6f to your computer and use it in GitHub Desktop.
Functions to help with code execution analysis in R
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
# how much memory did an execution use in MBs | |
mem_usage <- function(...){ | |
exprs <- as.list(match.call(expand.dots = FALSE)$...) | |
invisible(gc(reset = TRUE)) | |
start_mem <- sum(gc()[,2]) | |
lapply(exprs, eval, parent.frame()) | |
max_mem <- sum(gc()[,6]) | |
end_mem <- sum(gc()[,2]) | |
return(list(final_mem_used = as.numeric(end_mem - start_mem) | |
, max_mem_used = as.numeric(max_mem - start_mem) | |
) | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment