Skip to content

Instantly share code, notes, and snippets.

@MichaelChirico
Created February 23, 2018 03:50
Show Gist options
  • Save MichaelChirico/63ae2e4cf87079d9a45b7fb17082820e to your computer and use it in GitHub Desktop.
Save MichaelChirico/63ae2e4cf87079d9a45b7fb17082820e to your computer and use it in GitHub Desktop.
script to install a given commit of data.table & run a speed test of fread
library(devtools)
install_github('Rdatatable/data.table', quiet = TRUE,
ref = commandArgs(trailingOnly = TRUE))
library(data.table)
f = list.files('.', recursive = TRUE, pattern = '\\.csv$', full.names = TRUE)
ts = replicate(5L, {
t0 = Sys.time()
invisible(lapply(f, fread))
as.double(Sys.time() - t0)
})
cat(paste(ts, collapse = ','))
@HughParsonage
Copy link

HughParsonage commented Feb 24, 2018

One possible improvement would to create a local library for each commit and then point to that directory. The advantage being that you only need to install once per commit. (So if you choose to profile a different script you can just change the script without reinstalling.)

library(devtools)

Ref <- commandArgs(trailingOnly = TRUE)
if (!dir.exists(Ref)) {
  dir.create(Ref)

  devtools::install_github('Rdatatable/data.table', quiet = FALSE,
                           ref = Ref,
                           args = paste0('--library="', normalizePath(Ref, winslash = "/"), '"'))
} 

library(data.table, lib.loc = Ref)
library(microbenchmark)

mi <- as.data.frame(microbenchmark(Ref_DT = fread("DT-n-8.csv"), times = 2L))
mi[["commit"]] <- Ref
write.table(mi, paste0("fread-DT-n-8__", Ref, ".csv"))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment