Path: news.mathworks.com!not-for-mail From: "Joel " <joel.j.k.parker@nasa.gov> Newsgroups: comp.soft-sys.matlab Subject: Re: Speed difference between row and column vectors Date: Thu, 18 Apr 2013 15:51:13 +0000 (UTC) Organization: NASA Lines: 93 Message-ID: <kkp4ph$kj0$1@newscl01ah.mathworks.com> References: <kkp1tf$au2$1@newscl01ah.mathworks.com> <kkp3kd$gfd$1@newscl01ah.mathworks.com> Reply-To: "Joel " <joel.j.k.parker@nasa.gov> NNTP-Posting-Host: www-04-blr.mathworks.com Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: newscl01ah.mathworks.com 1366300273 21088 172.30.248.35 (18 Apr 2013 15:51:13 GMT) X-Complaints-To: news@mathworks.com NNTP-Posting-Date: Thu, 18 Apr 2013 15:51:13 +0000 (UTC) X-Newsreader: MATLAB Central Newsreader 2245329 Xref: news.mathworks.com comp.soft-sys.matlab:793833 "Steven_Lord" <slord@mathworks.com> wrote in message <kkp3kd$gfd$1@newscl01ah.mathworks.com>... > > > "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 Thanks for the reply. I'm using MATLAB R2013a 64-bit on Windows 7 Enterprise 64-bit. When I run your function colvec_test (displaying output instead of saving it to T), I get: >> colvec_test Elapsed time is 0.078862 seconds. Elapsed time is 0.079289 seconds. Elapsed time is 0.078867 seconds. >> When I run the contents of colvec_test from the command prompt, I get: >> [snip] Elapsed time is 0.392249 seconds. Elapsed time is 0.643703 seconds. Elapsed time is 9.023197 seconds. >>