f <- tempfile(fileext = ".npy")
np <- reticulate::import("numpy")
x <- np$random$rand(1000L, 1000L)
np$save(f, x)
microbenchmark::microbenchmark(
reticulate = {
x <- np$load(f)
},
grumpy = {
x <- grumpy::read_npy(f)
},
times = 1e3
)
Unit: milliseconds
expr min lq mean median uq max neval
reticulate 1.576664 1.767072 3.004239 1.885064 3.212363 64.25474 1000
grumpy 1.377934 1.584914 3.797477 1.844541 3.127293 79.06193 1000
## On platform that support it, lazy reading offers even better performance for large files
if (Sys.info()[["sysname"]] %in% c("Linux", "Darwin")) {
microbenchmark::microbenchmark(
reticulate = {
x <- np$load(f)
},
grumpy = {
x <- grumpy::read_npy(f, lazy = TRUE)
},
times = 1e3
)
}
Unit: microseconds
expr min lq mean median uq max neval
reticulate 1542.597 1723.787 2872.412 1889.880 3109.2270 71066.67 1000
grumpy 311.600 466.703 1299.047 584.604 857.6305 71185.41 1000