Skip to content

Instantly share code, notes, and snippets.

@moldach
Last active October 29, 2019 19:12
Show Gist options
  • Save moldach/46e7e254f68b3cf690076c899f40f2e4 to your computer and use it in GitHub Desktop.
Save moldach/46e7e254f68b3cf690076c899f40f2e4 to your computer and use it in GitHub Desktop.
Troubleshooting bench::mark with qs::qread()
library(bench)
library(qs)
library(sf)
library(cowplot)
# load ggplot
download.file("https://www.dropbox.com/s/ao0827vayr5u3vx/hawaii_agriculture_100m_basemap.rds?raw=1" , "hawaii_agriculture_100m_basemap.rds")
hawaii <- readRDS("hawaii_agriculture_100m_basemap.rds")
# bench mark saving
save_compressed <- bench::mark(saveRDS(hawaii, "hawaii_compressed.rds"), iterations = 50)
save_uncompressed <- bench::mark(saveRDS(hawaii, "hawaii_uncompressed.rds", compress = FALSE), iterations = 50)
save_qs <- bench::mark(qsave(hawaii, "hawaii.qs"), iterations = 50)
# bench mark reading
read_compressed <- bench::mark(hawaii <- readRDS("hawaii_compressed.rds"), iterations = 50)
read_uncompressed <- bench::mark(hawaii <- readRDS("hawaii_uncompressed.rds"), iterations = 50)
read_qs <- bench::mark(hawaii <- qread("hawaii.qs"), iterations = 50)
# combine
bench_save <- rbind(save_compressed, save_uncompressed, save_qs)
bench_read <- rbind(read_compressed, bench_read_uncompressed, read_qs)
# resort to system.time
# bench mark saving
system.time(saveRDS(hawaii, "hawaii_compressed.rds"))
system.time(saveRDS(hawaii, "hawaii_uncompressed.rds", compress = FALSE))
system.time(qsave(hawaii, "hawaii.qs")) # this freezes my 8Gb laptop and 32Gb workstation
# bench mark reading
system.time(hawaii <- readRDS("hawaii_compressed.rds"))
system.time(hawaii <- readRDS("hawaii_uncompressed.rds"))
system.time(hawaii <- qread("hawaii.qs"))
plot_01 <- df %>% dplyr::filter(io == "write") %>% ggplot(., aes(x=method, y=time, fill=method)) +
geom_bar(stat = "identity") + ggtitle("write time in seconds") + scale_fill_brewer(palette = "Set1") + theme_light() + theme(legend.position="none")
plot_02 <- df %>% dplyr::filter(io == "read") %>% ggplot(., aes(x=method, y=time, fill=method)) +
geom_bar(stat = "identity") + ggtitle("read time in seconds") + scale_fill_brewer(palette = "Set1") + theme_light() + theme(legend.position="none")
plot_grid(plot_01, plot_02)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment