[R] Why R is 200 times slower than Matlab ?

Wensui Liu liuwensui at gmail.com
Wed Apr 30 22:21:51 CEST 2008


Hi, ZD,
Your comment about speed is too general. Here is a benchmark
comparison among several languages and HTH.
http://www.sciviews.org/benchmark/index.html

On Wed, Apr 30, 2008 at 4:15 PM, Zhandong Liu
<zhandong at mail.med.upenn.edu> wrote:
> I am switching from Matlab to R, but I found that R is 200 times slower than
>  matlab.
>
>  Since I am newbie to R, I must be missing some important programming tips.
>
>  Please help me out on this.
>
>  Here is the function:
>  ## make the full pair-wise permutation of a vector
>  ## input_fc=c(1,2,3);
>  ## output_fc=(
>  1 1 1 2 2 2 3 3 3
>  1 2 3 1 2 3 1 2 3
>  );
>
>  grw_permute = function(input_fc){
>
>  fc_vector = input_fc
>
>  index = 1
>
>  k = length(fc_vector)
>
>  fc_matrix = matrix(0,2,k^2)
>
>  for(i in 1:k){
>
>  for(j in 1:k){
>
>  fc_matrix[index]  =  fc_vector[i]
>
>  fc_matrix[index+1]  =  fc_vector[j]
>
>  index = index+2
>
>  }
>
>  }
>
>  return(fc_matrix)
>
>  }
>
>  For an input vector of size 300. It took R 2.17 seconds to run.
>
>  But the same code in matlab only needs 0.01 seconds to run.
>
>  Am I missing sth in R.. Is there a away to optimize.  ???
>
>  Thanks
>
>  --
>  Zhandong Liu
>
>  Genomics and Computational Biology
>  University of Pennsylvania
>
>  616 BRB II/III, 421 Curie Boulevard
>  University of Pennsylvania School of Medicine
>  Philadelphia, PA 19104-6160
>
>         [[alternative HTML version deleted]]
>
>  ______________________________________________
>  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.
>



-- 
===============================
WenSui Liu
ChoicePoint Precision Marketing
Phone: 678-893-9457
Email : wensui.liu at choicepoint.com
Blog : statcompute.spaces.live.com



More information about the R-help mailing list