Path: news.mathworks.com!not-for-mail
From: "Julian Reichl" <julesreichl@yahoo.co.uk>
Newsgroups: comp.soft-sys.matlab
Subject: very slow vectorized code
Date: Thu, 24 Apr 2008 06:50:04 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 36
Message-ID: <fupais$8av$1@fred.mathworks.com>
Reply-To: "Julian Reichl" <julesreichl@yahoo.co.uk>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1209019804 8543 172.30.248.35 (24 Apr 2008 06:50:04 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 24 Apr 2008 06:50:04 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1043246
Xref: news.mathworks.com comp.soft-sys.matlab:464908


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