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