Created
September 16, 2019 16:56
-
-
Save bobjansen/5b2b68fd9c689c702e0e8f60c0f47644 to your computer and use it in GitHub Desktop.
Mesh Test
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
# Rscript mesh <- test.R | |
# LD_PRELOAD=libmesh.so Rscript mesh_test.R | |
#library(data.table) | |
#library(microbenchmark) | |
doDataTable <- FALSE | |
pid <- Sys.getpid() | |
GetMemSize <- function() { | |
pidStatus <- system2( | |
'cat', args = paste0('/proc/', pid, '/status'), | |
stdout = TRUE | |
) | |
rssText <- pidStatus[grepl('VmRSS', pidStatus)] | |
# https://stackoverflow.com/a/14544445/862288 | |
matches <- regmatches(rssText, gregexpr("[[:digit:]]+", rssText)) | |
as.integer(unlist(matches)) | |
} | |
cat('Running with pid' , pid, '\n') | |
CreateTable <- function(n = 1e4L) { | |
if (doDataTable) { | |
data.table::data.table( | |
c1 = sample(letters, size = n, replace = TRUE), | |
c2 = sample(LETTERS, size = n, replace = TRUE), | |
c3 = runif(n) | |
) | |
} else { | |
data.frame( | |
c1 = sample(letters, size = n, replace = TRUE), | |
c2 = sample(LETTERS, size = n, replace = TRUE), | |
c3 = runif(n) | |
) | |
} | |
} | |
baseName <- 'tbl' | |
staticCounter <-1L | |
RunFun <- function(reps = 10L) { | |
set.seed(staticCounter) | |
tableEnv <- new.env() | |
rsses <- rep(NA, reps) | |
for (i in 1:reps) { | |
size <- sample(1e4:1e4, size = 1L) | |
dtName <- paste0(baseName, i) | |
assign(dtName, CreateTable(size), envir = tableEnv) | |
if (runif(1L) < 0.5) { | |
delThis <- sample(ls(envir = tableEnv), size = 1L) | |
rm(list = c(delThis), envir = tableEnv) | |
} | |
rsses[[i]] <- GetMemSize() | |
} | |
cat(sprintf("%d tables removed\n", reps - length(ls(envir = tableEnv)))) | |
cat(sprintf("%03d Max VmRss:\t%d kb\n", staticCounter, max(rsses))) | |
staticCounter <<- staticCounter + 1L | |
} | |
for (i in 1:3) { | |
RunFun() | |
} | |
#print(microbenchmark::microbenchmark( | |
# RunFun(), | |
# times = 3L | |
#)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment