[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: are cell arrays slow?
From: |
kensmith |
Subject: |
Re: are cell arrays slow? |
Date: |
Mon, 27 Aug 2007 07:38:59 -0700 |
User-agent: |
KMail/1.9.1 |
On Monday 27 August 2007 02:13, Bertrand Roessli wrote:
> Hello,
>
> I have tried the following test code and I have the
> feeling that working with cell arrays is slow. Do I make a mistake
> somewhere?
No mistake is obvious to me.
>
>
> nr=1000;
>
> for i=1:nr
> mom.mx=i;
> mom.my=2*i;
> a{i}=mom;
> endfor
>
>
> tic;
> [[a{1:nr}].mx].+[[a{1:nr}].my];
> toc
I am almost surprised that this takes much time at all. If the
calculation is done as shown, three arrays need to be allocated. This
may take longer than doing the "+". I would have expected there to be
some optimizing that would have reduced the amount of allocating and
de-allocating. Since this statement produces no result, a very good
optimizer would have reduced it to nothing.
> tic;
> for i=1:nr
> a{i}.mx.+a{i}.my;
> endfor
> toc
Here we are looping but not allocating. Perhaps the loop method has
been very optimized.
address@hidden