library(ggplot2)
library(microbenchmark)
library(parallel)
options(mc.cores=3)

list_size <- seq(1000, 100000, by=10000)

list_res <- mclapply(list_size, function(i) {
  mb <- microbenchmark(
  rlist={
    lst <- list()
    for (j in seq_len(i)) {
      lst <- c(lst, j)
    }
  },
  dynlist={
    lst <- dynlist()
    for (j in seq_len(i)) {
      lst$append(j)
    }
  }, times=10)
  class(mb) <- "data.frame"
  mb$i <- i
  mb
})

res <- do.call(rbind, list_res)

p <- ggplot(res, aes(x=i, y=time, color=expr)) + geom_point() + geom_smooth(se=FALSE)
p <- p + scale_y_log10()
p <- p + scale_x_log10()
p


vsbuffalo/rivr documentation built on May 3, 2019, 7:07 p.m.