Created
February 17, 2017 12:20
-
-
Save Rekyt/39f6a3c5b364fb490c006ddf7586dd55 to your computer and use it in GitHub Desktop.
Compare speed of functions with across parameter range
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
| # 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