Skip to content

Instantly share code, notes, and snippets.

@robertjwilson
Last active April 17, 2017 17:46
Show Gist options
  • Save robertjwilson/f0fc9b426f294ca0ccc79ae506e77e24 to your computer and use it in GitHub Desktop.
Save robertjwilson/f0fc9b426f294ca0ccc79ae506e77e24 to your computer and use it in GitHub Desktop.
x <- 1:10^4
sum_all <- function(x){
sum_all <- 0
for(i in 1:length(x))
sum_all <- sum_all + x[i]
sum_all
}
sum_all_cmp <- compiler::cmpfun(sum_all)
rbenchmark::benchmark(y <- sum_all(x), y <- sum_all_cmp(x))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment