Skip to content

Instantly share code, notes, and snippets.

@symbolrush
Created March 22, 2016 08:26
Show Gist options
  • Select an option

  • Save symbolrush/304aa1711faf9220b8ec to your computer and use it in GitHub Desktop.

Select an option

Save symbolrush/304aa1711faf9220b8ec to your computer and use it in GitHub Desktop.
short speed test data.frame vs. data.table
library(data.table)
dt <- data.table(a = c(1:10000), b = rep(c("a","b","c"), length = 10000))
df <- data.frame(a = c(1:10000), b = rep(c("a","b","c"), length = 10000))
microbenchmark::microbenchmark(dt[dt$b == "b",], times = 1000, unit = "us")
microbenchmark::microbenchmark(df[df$b == "b",], times = 1000, unit = "us")
microbenchmark::microbenchmark(dt$a[dt$b == "b"], times = 1000, unit = "us")
microbenchmark::microbenchmark(df$a[df$b == "b"], times = 1000, unit = "us")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment