Path: news.mathworks.com!not-for-mail
From: Bill Nell <bnell@mathworks.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: very slow vectorized code
Date: Fri, 25 Apr 2008 11:26:17 -0400
Organization: The MathWorks, Inc.
Lines: 54
Message-ID: <fust6p$r99$1@fred.mathworks.com>
References: <fupais$8av$1@fred.mathworks.com> <fupbim$hs6$1@fred.mathworks.com>
NNTP-Posting-Host: bnell-deb4-64.dhcp.mathworks.com
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: fred.mathworks.com 1209137177 27945 144.212.108.160 (25 Apr 2008 15:26:17 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 25 Apr 2008 15:26:17 +0000 (UTC)
User-Agent: Icedove 1.5.0.10 (X11/20070328)
In-Reply-To: <fupbim$hs6$1@fred.mathworks.com>
Xref: news.mathworks.com comp.soft-sys.matlab:465206


Julian Reichl wrote:
> I just tried commenting out all the other code within the loop 
> i=1:28305
> ...
> end
> and it bought that e(:,:)=0;
> statement back to 0.04s. So could this mean that there is
> some memory issue?
> 
> "Julian Reichl" <julesreichl@yahoo.co.uk> wrote in message
> <fupais$8av$1@fred.mathworks.com>...
>> Hi all,
>> I have a problem that I can't figure out.  I have two
>> versions of some code, one vectorised, the other not. The
>> vectorised version runs WAY slower for single repeats - ~17
>> seconds cf. 0.3 seconds.
>>
>> The profiler tells me that pretty much every line of the
>> code is a lot slower in the vectorised version. Even simple
>> things like 
>>
>> e=repmat(1,1);
>> for i=1:28305
>> e(:,:)=0;
>> end
>>
>> (the 1:28305 is a time-stepping loop and can't be removed)
>> takes 0.39 s inside the vectorised code (not including the
>> repmat), whereas in the command line it takes less than a
>> 10th of that time.
>> if, in the same code (the vectorised version), I replace it
>> with 
>>
>> for i=1:28305
>> e=0;
>> end
>>
>> (which is fine for this example because it's a 1x1, but not
>> for my application), the time for that function drops,
>> again, to ~ a 10th. 
>>
>> I really hope someone has an idea!!!
>>
>> thanks
>>
>> Julian
>>
> 

Julian,
If you are just trying to set the contents of e to 0 then just use
e(:) = 0 instead of e(:,:) = 0.

Bill