Skip to content

Instantly share code, notes, and snippets.

@Rekyt
Created February 17, 2017 12:20
Show Gist options
  • Select an option

  • Save Rekyt/39f6a3c5b364fb490c006ddf7586dd55 to your computer and use it in GitHub Desktop.

Select an option

Save Rekyt/39f6a3c5b364fb490c006ddf7586dd55 to your computer and use it in GitHub Desktop.
Compare speed of functions with across parameter range
# Programmatically use 'microbenchmark()'
# Author: Matthias Grenié
library(microbenchmark)
# Get two functions
my_func = function(x) {
5^x
}
my_func2 = function(x) {
3^x
}
# Generate list of unevaluated expression for both functions
uneval_list = lapply(1:4, function(y) {
# Coalesc and forward expressions not evluated
uneval_expr = c(call("my_func", x = y),
call("my_func2", x = y))
# Names of implementation
names(uneval_expr) = paste0(c("power5.", "power3."), x)
return(uneval_expr)
})
uneval_list = unlist(uneval_list, recursive = FALSE)
microbenchmark(list = uneval_list)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment