compiler provides a byte code compiler for R, which offers the possibility of compiling your functions before executing them. Among other things, this speeds up those embarrassingly slow for loops that you've been using:
> myFunction<-function() { for(i in 1:10000000) { 1*(1+1) } }
> library(compiler)
> myCompiledFunction <- cmpfun(myFunction) # Compiled function
>
> system.time( myFunction() )
user system elapsed
10.002 0.014 10.021
> system.time( myCompiledFunction() )
user system elapsed
0.692 0.008 0.700
That's 14 times faster!
Functions written in C (imported using Rcpp) are still much faster than the compiled byte code, but for those of us who
- don't know C,
- know C but prefer to write code in R,
- know C but don't want to rewrite functions that we've already written in R,
compiler offers a great way of speeding up computations. It's included in the recommended R packages since R 2.13 (meaning that it comes with your basic R installation) and since R 2.14 most standard functions are already compiled. If you still are running an older version of R it's definitely time to update.
Hi Mans,
ReplyDeleteYou might be interested in a post I recently wrote about using the JIT in the compiler package:
http://www.r-statistics.com/2012/04/speed-up-your-r-code-using-a-just-in-time-jit-compiler/
Thanks for the link Tal, that was a very interesting read! :)
ReplyDeleteThanx for pointing me to this corner of R!
ReplyDeleteGreatings from a former UU post-doc (BioMedicum)!
Manohar Reddy
ReplyDeletedataentryoutsource2india@gmail.com
http://dataentryoutsource2india.com/
Dataentryoutsource2india.com specializes in providing excellent services on Data Entry, Data Processing, Document Scanning Services, Data Conversion service, E-Publishing service, XML Tagging service, Online Data Extraction, Image Editing/Graphic Support, Order Processing, Catalog Processing and lots more with high quality and very affordable price.
Manohar Reddy
ReplyDeletehttp://dataentryoutsource2india.com
dataentryoutsource2india@gmail.com
Dataentryoutsource2india.com specializes in providing excellent services on Data Entry, Data Processing, Document Scanning Services, Data Conversion service, E-Publishing service, XML Tagging service, Online Data Extraction, Image Editing/Graphic Support, Order Processing, Catalog Processing and lots more with high quality and very affordable price.
Thanks great blog
ReplyDelete