[R] Measuring CPU time
. .
xkziloj at gmail.com
Thu Sep 1 14:10:18 CEST 2011
Why time is increasing for the same operation?
I was expecting +/- the same time for each n.
Thanks in advance.
bench <- function(f1, n, ...) {
t <- 0
for(i in 1:n) {
func <- function(x) x^2
expr <- list(...)[1]
f1 <- c("system.time(y <- ", gsub("XXX",expr,f1),")[3]")
t1 <- eval(parse(text = f1))
printf("time %d: %f\n", i, t1)
t <- t + t1
}
t <- t/n
printf("mean time: %f", t)
}
bench("func(XXX)", 10, "1:100")
More information about the R-help
mailing list