[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
are cell arrays slow?
From: |
Bertrand Roessli |
Subject: |
are cell arrays slow? |
Date: |
Mon, 27 Aug 2007 11:13:58 +0200 |
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?
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
tic;
b=[a{1:nr}];
[b.mx].+[b.my];
toc
tic;
for i=1:nr
a{i}.mx.+a{i}.my;
endfor
toc
tic;
i=1:nr;
b=[a{i}];
[b.mx].+[b.my];
toc
tic;
i=1:nr;
[i].+2.*[i];
toc
Elapsed time is 0.803093 seconds.
Elapsed time is 0.391693 seconds.
Elapsed time is 0.049988 seconds.
Elapsed time is 0.388489 seconds.
Elapsed time is 0.000381 seconds.
What puzzles me is that the for-loop is faster.
Thank you,
B. Roessli
--
Dr. Bertrand Roessli
Laboratory for Neutron Scattering
Paul Scherrer Institut and ETH Zurich
CH-5232 Villigen PSI
Tel.: +41 56 310 44 01
- are cell arrays slow?,
Bertrand Roessli <=