Skip to content

Instantly share code, notes, and snippets.

@slwu89
Created February 27, 2017 16:44
Show Gist options
  • Save slwu89/3e23bb210913d2b807136f2eaffc90fb to your computer and use it in GitHub Desktop.
Save slwu89/3e23bb210913d2b807136f2eaffc90fb to your computer and use it in GitHub Desktop.
testing out speed of R "compiler" package with Vectorize
library(compiler)
inFun <- Vectorize(function(x,y,z){
return((x^2)+y*z)
},SIMPLIFY = FALSE)
inFun1 <- cmpfun(Vectorize(function(x,y,z){
return((x^2)+y*z)
},SIMPLIFY = FALSE),options = list(optimize=1))
inFun2 <- cmpfun(Vectorize(function(x,y,z){
return((x^2)+y*z)
},SIMPLIFY = FALSE),options = list(optimize=3))
library(microbenchmark)
microbenchmark(
inFun(x=1:5000,y=2,z=3),
inFun1(x=1:5000,y=2,z=3),
inFun2(x=1:5000,y=2,z=3),times = 500
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment