[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [igraph] Speed comparison of R and C

From: Gábor Csárdi
Subject: Re: [igraph] Speed comparison of R and C
Date: Tue, 8 Feb 2011 16:03:54 +0100

There is not much to add to this thread, but it might be worth noting
that R doesn't have much vectorization support, at least the last time
I looked at it sapply and lapply were just as slow as a for loop. E.g:

 l <- 1:50000
 system.time(tmp <- sapply(l, function(x) mean(l)))
   user  system elapsed
  3.589   0.005   3.595
 system.time(for (i in l) mean(l))
   user  system elapsed
  3.455   0.003   3.458

I don't think that the attributes are slowing down things much. R
igraph uses R for handling the attributes, e.g. for creating a
subgraph is just an R indexing operation on the attributes. Collecting
them in a single data frame might help a bit, but I don't think the
difference is big. But I've never made any measurement for this, so
this is somewhat speculative.

What can be slow is R language constructs that are executed a lot of
times, e.g. for loops or sapply, lapply, etc. Usually you only need to
write these is C.


On Tue, Feb 8, 2011 at 3:33 PM, Tamas Nepusz <address@hidden> wrote:
> Dear William,
>> I did an experiment as follow:
>> 1. Create a full graph
>> 2. For each edges, attach two attributes
>> 3. For all edges, randomly pick an edge and read/write its value
>> In R:
>> 100 nodes, 4950 edges: 4 sec
> Can you send us your actual code please? I'm pretty sure that you are
> not making use of R's vectorization support and that's why you are
> measuring such large run times. Looping (e.g., using a for loop) is very
> slow in R, but in most cases it can be avoided.
> --
> T.
> _______________________________________________
> igraph-help mailing list
> address@hidden
> http://lists.nongnu.org/mailman/listinfo/igraph-help

Gabor Csardi <address@hidden>     UNIL DGM

reply via email to

[Prev in Thread] Current Thread [Next in Thread]