views:

553

answers:

3

R is a scripting language, but is it fast? It seems like a lot of the packages used by R are actually compiled from C. Does anyone have an example of how using languages like C or Java instead of R caused a noticeable increase in speed? Is there a fair benchmark somewhere? Is there a C (or any other compiled) library that has many of the C functions compiled into it that can be used for comparison?

I really like R, but am concerned that it will be way too slow and I will have to retreat back to C anyway.

EDIT: I would also like to hear of what makes R slow down. Are there certain unoptimized libraries? Are there certain ways to use R to keep it running fast?

+5  A: 

No, R is not fast, but it is very easy to use and a very efficient tool if you need to do a lot of stats work.

However, it's not hard to write R functions in C, so if you find you're doing a lot of work in R and there's one function that's slowing you down a lot, you can always write a C version of that function.

Good application of Amdahl's law can get you quickly building functionality using easy to write code in R with the very few speed critical sections using fast C code.

I don't have a specific example that I could conveniently show here, but anecdotally I can tell you that getting working code up in R was fast, but that some functions that took 30 min to run in R then took <1 min when rewritten in C.

jharlap
Good example and practical advice.
User1
These are all wonderful answers so far, but I like the "here's how to make it faster" advice. So I selected this answer.
User1
+9  A: 

That is a loaded question, and there are many answers such as

  • vectorization
  • just-in-time compilation (Ra, jit)
  • compiled code
  • parallel execution

many of which are covered in the Task View on High-Performance Computing and my tutorials on 'Intro to High Performance Computing with R' (Dec 2008 version, July 2009 version).

Dirk Eddelbuettel
+4  A: 

I agree with Dirk's answer.

To partially answer your question on benchmarks, I suggest the following thread on the R Wiki, where they compare different implementations of a simple algorithm. It's illustrates some of the tradeoffs between vectorized R code and R extensions written in C.

Christopher DuBois