help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Slowdown in assignment mystery


From: John Swensen
Subject: Re: Slowdown in assignment mystery
Date: Wed, 13 Jun 2007 11:08:25 -0400
User-agent: Thunderbird 2.0a1 (X11/20060807)

David Bateman wrote:
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.



This did the trick. Using cell arrays, it runs as fast as the single image captures. Thank you very, very much.

John Swensen


reply via email to

[Prev in Thread] Current Thread [Next in Thread]