From: "John D'Errico" <woodchips@rochester.rr.com>
Path: news.mathworks.com!newsfeed-00.mathworks.com!webcrossing
Newsgroups: comp.soft-sys.matlab
Subject: Re: decrease in speed due to appending a row vecto
Message-ID: <ef580c1.8@webcrossing.raydaftYaTP>
Date: Fri, 25 May 2007 10:35:59 -0400
References: <ef580c1.1@webcrossing.raydaftYaTP> <ef580c1.2@webcrossing.raydaftYaTP> <1180055867.161190.184610@u36g2000prd.googlegroups.com> <ef580c1.5@webcrossing.raydaftYaTP> <ef580c1.7@webcrossing.raydaftYaTP>
Lines: 110
NNTP-Posting-Host: 66.66.16.32
MIME-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
Xref: news.mathworks.com comp.soft-sys.matlab:411084



Eric Sampson wrote:
>
>
> John D'Errico wrote:
>>
>>
> (snip)
>> Some quick testing shows a structure and
>> a cell array to be similar in time and
>> memory here.
>>
>> tic
>> for i = 1:1000
>> a(i).X =rand(1,3);
>> end,
>> whos a
>> toc
>>
>> Name Size Bytes Class Attributes
>> a 1x1000 84064 struct
>>
>> Elapsed time is 0.023403 seconds.
>>
>> tic
>> for i = 1:1000
>> b{i} =rand(1,3);
>> end
>> whos b
>> toc
>>
>> Name Size Bytes Class Attributes
>> b 1x1000 84000 cell
>>
>> Elapsed time is 0.022017 seconds.
>>
>> The question is, do these scale well with
>> larger numbers of append operations?
>>
>> tic
>> for i = 1:100000
>> a(i).X =rand(1,3);
>> end
>> whos a
>> toc
>>
>> Name Size Bytes Class Attributes
>> a 1x100000 8400064 struct
>>
>> Elapsed time is 118.482410 seconds.
>>
>> This has grown by more than 100x. In fact,
>> it grew in time by a factor of roughly
>> 10000, or 100^2. It is this quadratic
>> growth in time that I was trying to avoid
>> with the growdata codes.
>>
>> How about growdata2 here?
>>
>> tic
>> g=growdata2;
>> for i = 1:100000
>> g(rand(1,3))
>> end
>> g=g();
>> whos g
>> toc
>>
>> Name Size Bytes Class Attributes
>> g 100000x3 2400000 double
>>
>> Elapsed time is 12.672389 seconds.
>>
>> So if you are appending only a few thousand
>> elements, then either the structure or the
>> cell array will work quite well. If you
>> expect to append hundreds of thousands or
>> more chunks, then the hybrid approach in
>> the growdata tools is still more reasonable.
>>
>> Your mileage may vary with a newer release
>> yet than R2006b. I've not gotten the latest
>> release installed until I install a new OS
>> version here.
>>
>> John
>
>
> John, I can't reproduce your results on my computer (winxp32), on
> R2006b or R2007a. The cell and struct both take virtually the same
> amount of time, about 20sec for the 100000 case. Growdata is still
> faster, of course, coming in at about 10sec.
>
> Regards,
> Eric Sampson
> The MathWorks, Inc.
  
The cell and the struct were both the same
for me, but it was definitely 2 minutes.

Its possible this is a CPU issue, since
I'm running on a Mac, or a memory limitation
issue (3/4 gig of ram.) I was running a web
browser on the side, so there might have
been a virtual problem.

I'll re-run the test this afternoon with
as little else competing for ram as possible
(after I also reboot.)

John