[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Slowdown in assignment mystery
From: |
David Bateman |
Subject: |
Re: Slowdown in assignment mystery |
Date: |
Wed, 13 Jun 2007 16:19:03 +0200 |
User-agent: |
Thunderbird 1.5.0.7 (X11/20060921) |
John Swensen wrote:
> I have a fairly simple example that has me perplexed. Below are the two
> code listings. As a little background, the ocw_grab_frame() function
> returns a uint8 matrix. Also, this computer has 4GB of RAM, and we are
> running this from a Linux box with X11 *not* running so less than 300MB
> is in use before running octave and the swap hasn't been touched. I
> would expect the first listing to run the fastest. Since we are
> pre-allocating the space for the images, then it seems like it should be
> a simple memcpy into the new buffer. Contrary to this assumption, the
> first listing has a mean(tocs)=200ms and std(tocs)=10ms, where the
> second listing has a mean(tocs)=11.2ms and std(tocs)=1.5ms. I am a
> little confused, so maybe someone has a suggestion.
>
> John Swensen
>
> Listing 1:
> imgs = uint8(zeros(480,640,100));
> for I=1:100
> tic;
> imgs(:,:,I) = ocw_grab_frame();
> tocs(I) = toc;
> end
>
> Listing 2:
> for I=1:100
> tic;
> img = ocw_grab_frame();
> tocs(I) = toc;
> end
>
Thinking about it further, the indexed assignment is expensive.
Something like
imgs = cell(1,100)
for I=1:100
imgs{I} = ocw_grab_frame();
end
might be better. If you need it in a 3-D matrix, then something like
imgs = cell([1,1,100])
for I=1:100
imgs{I} = ocw_grab_frame();
end
imgs = cell2mat(imgs);
might work..
D.
--
David Bateman address@hidden
Motorola Labs - Paris +33 1 69 35 48 04 (Ph)
Parc Les Algorithmes, Commune de St Aubin +33 6 72 01 06 33 (Mob)
91193 Gif-Sur-Yvette FRANCE +33 1 69 35 77 01 (Fax)
The information contained in this communication has been classified as:
[x] General Business Information
[ ] Motorola Internal Use Only
[ ] Motorola Confidential Proprietary