Skip to content
Prev 312152 / 398506 Next

code optimisation problem

Hello,

Package 'compiler' is good at optimizing for loops. Try the following.


#install.packages('compiler')
library(compiler)
f1.c <- cmpfun(f1)

N <- 1e6
x <- rnorm(N)
system.time(f1(x, 10))
    user  system elapsed
    6.77    0.06    6.83
system.time(f1.c(x, 10))
    user  system elapsed
    2.57    0.00    2.57


Hope this helps,

Rui Barradas

Em 27-11-2012 21:43, 47 escreveu: