Last active
December 3, 2019 00:07
-
-
Save ldaniel/632ff4049dc83e54f8c12fe2ddea4a67 to your computer and use it in GitHub Desktop.
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
install.packages("rbenchmark") | |
library(compiler) | |
library(rbenchmark) | |
enableJIT(level = 3) | |
#enableJIT(level = 0) | |
my_mean = function(x) { | |
total = 0 | |
n = length(x) | |
for(i in 1:n) | |
total = total + x[i]/n | |
total | |
} | |
cmp_mean = cmpfun(my_mean) | |
x = rnorm(100) | |
benchmark(my_mean(x), cmp_mean(x), mean(x), | |
columns=c("test", "elapsed", "relative"), | |
order="relative", replications=5000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment