[R] An "R is slow"-article

Duncan Murdoch murdoch at stats.uwo.ca
Wed Jan 9 16:57:29 CET 2008


On 1/9/2008 10:25 AM, Gustaf Rydevik wrote:
> Hi all,
> 
> Reading the wikipedia page on R, I stumbled across the following:
> http://fluff.info/blog/arch/00000172.htm
> 
> It does seem interesting that the C execution is that much slower from
> R than from a native C program. Could any of the more technically
> knowledgeable people explain why this is so?

That conclusion isn't supported by his test. The main source of the 
difference is interpreting the loop:

test_ct <- 10000
x       <- matrix(c(300, 860, 240, 380), nrow=2)
for (i in 1:test_ct)
     {fisher.test(x)}

If he wanted to show that R makes C go slower, he should have put 
together an example that spent most of its time in C, without returning 
to R 10000 times.  For example, make the entries in that table 1000 
times larger, and do the test just once:

 > x       <- matrix(c(300000, 860000, 240000, 380000), nrow=2)
 > fisher.test(x)

This takes about 20 seconds on my PC, and I'd guess it would take about 
the same amount of time in this author's pure C implementation.

My own experience is that R is about 100 times slower than pure C, and 
usually it doesn't matter.  In cases where it does, I'll  move the 
calculations into C.

If I followed Blair's advice and did everything in C, then development 
would take much longer, the code would be much buggier (even his example 
has bugs, and he admits it!!) and all those cases where R is fast enough 
would just never get done.

Duncan Murdoch

> 
> The author also have some thought-provoking opinions on R being
> no-good and that you should write everything in C instead (mainly
> because R is slow and too good at graphics, encouraging data
> snooping). See  http://fluff.info/blog/arch/00000041.htm
>  While I don't agree (granted, I can't really write C), it was
> interesting to read something from a very different perspective than
> I'm used to.
> 
> Best regards,
> 
> Gustaf
> 
> _____
> Department of Epidemiology,
> Swedish Institute for Infectious Disease Control
> work email: gustaf.rydevik at smi dot ki dot se
> skype:gustaf_rydevik
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.




More information about the R-help mailing list