Created
July 4, 2018 15:45
-
-
Save vpnagraj/0e348374464cdf8941fb139217e33088 to your computer and use it in GitHub Desktop.
benchmarking `svSocket` versus base `load` versus `redis`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(microbenchmark) | |
library(redux) | |
library(svSocket) | |
# clear workspace | |
rm(list = ls()) | |
# set up svSocket | |
startSocketServer() | |
con <- socketConnection(host = "localhost", port = 8888, blocking = FALSE) | |
# set up redis connection | |
r <- hiredis() | |
# generate data to cache | |
set.seed(123) | |
x <- rnorm(1e5) | |
# cache data | |
save(x, file = "x.rda") | |
evalServer(con, x, x) | |
r$SET("x", object_to_bin(x)) | |
rm(x) | |
m <- | |
microbenchmark( | |
load = load("x.rda"), | |
svsocket = evalServer(con, x), | |
redis = bin_to_object(r$GET("x")), | |
times = 10 | |
) | |
m | |
load("x.rda") | |
y <- evalServer(con, x) | |
z <- bin_to_object(r$GET("x")) | |
all.equal(mean(x),mean(y),mean(z)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nb
redux::hiredis()
needs to connect to a runningredis
server