Skip to content

Instantly share code, notes, and snippets.

@bobjansen
Created September 16, 2019 16:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bobjansen/5b2b68fd9c689c702e0e8f60c0f47644 to your computer and use it in GitHub Desktop.
Save bobjansen/5b2b68fd9c689c702e0e8f60c0f47644 to your computer and use it in GitHub Desktop.
Mesh Test
# 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