Path: news.mathworks.com!not-for-mail
From: "Steven_Lord" <slord@mathworks.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Speed difference between row and column vectors
Date: Thu, 18 Apr 2013 11:31:26 -0400
Organization: MathWorks
Lines: 73
Message-ID: <kkp3kd$gfd$1@newscl01ah.mathworks.com>
References: <kkp1tf$au2$1@newscl01ah.mathworks.com>
NNTP-Posting-Host: ah-slord.dhcp.mathworks.com
Mime-Version: 1.0
Content-Type: text/plain;
	format=flowed;
	charset="UTF-8";
	reply-type=response
Content-Transfer-Encoding: 7bit
X-Trace: newscl01ah.mathworks.com 1366299085 16877 172.28.9.169 (18 Apr 2013 15:31:25 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 18 Apr 2013 15:31:25 +0000 (UTC)
In-Reply-To: <kkp1tf$au2$1@newscl01ah.mathworks.com>
X-Priority: 3
X-MSMail-Priority: Normal
Importance: Normal
X-Newsreader: Microsoft Windows Live Mail 14.0.8089.726
X-MimeOLE: Produced By Microsoft MimeOLE V14.0.8089.726
Xref: news.mathworks.com comp.soft-sys.matlab:793832



"Joel " <joel.j.k.parker@nasa.gov> wrote in message 
news:kkp1tf$au2$1@newscl01ah.mathworks.com...
> Can anyone tell what's going on here? I have a hard time believing MATLAB 
> is so much slower when building column vectors.
>
>>> tic; for i=1:1e6; x=5.*[1, 2, 3]; end; toc
> Elapsed time is 0.389357 seconds.
>>> tic; for i=1:1e6; x=5.*([1, 2, 3]'); end; toc
> Elapsed time is 0.620597 seconds.
>>> tic; for i=1:1e6; x=5.*[1; 2; 3]; end; toc
> Elapsed time is 8.928639 seconds.
>
> They delay seems to not be in the multiplication operation, because in the 
> second example, the multiplication happens after the transpose.
>
> Thoughts?

1) What version of MATLAB are you using?
2) What operating system are you using?
3) Are you doing this in a function, in a script, or at the command prompt?
4) What else was going on when that third loop ran? Was some other 
application chewing up your system memory, requiring the OS to spend time 
swapping that application? Was something "phoning home" and again, using up 
your system's processing power for a little bit? My suspicion is that 
something started during the last 10% or so of the second loop's execution 
(causing a small slowdown) and continued through the entirety of the third 
loop's execution (causing a large slowdown.)

I was not able to reproduce these results using a function in release R2013a 
on my 64-bit Windows machine. All the elements of mt from the code below 
were fairly close to one another.

T = zeros(10, 3);
for k = 1:10
    T(k, :) = colvec_test;
end
mt = mean(T)


where:

function T = colvec_test
T = zeros(1, 3);
tic;
for i=1:1e6;
    x=5.*[1, 2, 3];
end;
tx = toc;
T(1) = tx;

tic;
for i=1:1e6;
    x=5.*([1, 2, 3]');
end;
tx = toc;
T(2) = tx;

tic;
for i=1:1e6;
    x=5.*[1; 2; 3];
end;
tx = toc;
T(3) = tx;


-- 
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on 
http://www.mathworks.com