help-octave
[Top][All Lists]
Advanced

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

Re: Slowdown in assignment mystery


From: Søren Hauberg
Subject: Re: Slowdown in assignment mystery
Date: Wed, 13 Jun 2007 15:33:06 +0200
User-agent: Thunderbird 1.5.0.12 (X11/20070604)

John Swensen skrev:
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
I don't know how the 3D array is organised in memory, but it is possible that one image is scattered all over the 3D array. If that is the case then you will write all over the memory which will be slow (you will have a bad cache access pattern). Perhaps that's the issue?

Søren


reply via email to

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