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

Douglas Bates bates at stat.wisc.edu
Thu May 1 15:31:33 CEST 2008


On 5/1/08, Shige Song <shigesong at gmail.com> wrote:
> Will the use of jit improve performance of use contributed packages such as
>  lme4? Thanks.

A technology like a byte-compiler or a just-in-time compiler will
change the performance of interpreted code.  It will not change the
performance of compiled code.  My intent is that the compute-intensive
parts of the functions in the lme4 package are performed in compiled
code.

You could profile the execution of a call to lmer that is taking a
long time and see where the time is being spent.  See ?Rprof for
details.

An even simpler measure is to add the optional argument  verbose =
TRUE in a call to lmer and watch the output of the iterations.
Everything from the appearance of the first iteration output to the
appearance of the last iteration output takes place in a single .Call
to a C function mer_optimize.  Performance during that period will
depend on the C compiler used, the level of optimization used, the use
of an accelerated BLAS (which sometimes can be counter-intuitive, we
have seen situations where use of an accelerated BLAS slowed down the
execution) and, of course, your hardware.  Also, during that call the
memory profile should stay essentially constant.  There is some
allocation and freeing of memory taking place during that call but
only a few, relatively small, chunks are involved.

I just realized that I am speaking about the behavior of the
development version of the lme4 package, available on R-forge.  The
release version is similar but not quite as tightly coded.

As indicated above, the first step in optimizing any code should
always be to profile the execution of the code and R does provide
tools for that.

>
>  Shige
>
>
>  On Thu, May 1, 2008 at 7:31 AM, Nelson Castillo <nelsoneci at gmail.com> wrote:
>
>  > On Wed, Apr 30, 2008 at 6:27 PM, Gabor Grothendieck
>  > <ggrothendieck at gmail.com> wrote:
>  > > Aside from optiming your code by making use of R functions
>  > >  that use C underneath as much as possible the big difference
>  > >  between R and Matlab is Matlab's just-in-time compilation of
>  > >  code.  When that was introduced in Matlab huge speedups of
>  > >  Matlab programs were noticeable.
>  > >
>  > >  For R, there is a new package on CRAN, jit, that
>  > >  aims to provide similar speedups.
>  >
>  > http://www.milbo.users.sonic.net/ra/index.html
>  >
>  > Great! I just found out about ra. In Python I love psyco and I guess I
>  > will test
>  > ra soon.
>  >
>  > Thanks,
>  > N.-
>  >
>  > --
>  > http://arhuaco.org
>  >
>  > ______________________________________________
>  > 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.
>  >
>
>
>         [[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.
>



More information about the R-help mailing list