From help-octave-request at bevo dot che dot wisc dot edu Wed Nov 5 13:14:18 2003 Subject: Re: simple matrix problem From: "Dmitri A. Sergatskov" To: taltman at lbl dot gov CC: help-octave Date: Wed, 05 Nov 2003 12:13:52 -0700 taltman at lbl dot gov wrote: > On Nov 5, 2003 at 2:47pm, Geraint Paul Bevan wrote: > > g.beva >data = [ data ( : , 1 ) , detrend ( data ( : , 2 ) ) ] > > Not to knit-pick, but an in-place assignment is faster than > re-allocating memory via the [...] operator: > > --- > octave> version > ans = 2.1.50 > octave> A = rand(50,50); > octave> tic;A(:,1) = rand(50,1);toc > ans = 0.0013770 > octave> tic;A = [ rand(50,1), A(:,2:50)];toc > ans = 0.0026010 > --- > Though I do not disagree with the conclusion I do not think those number make much sense (tic;toc timing is not that accurate): [dima at tumbleweed dima]$ octave GNU Octave, version 2.1.50 (i686-pc-linux-gnu). ... octave:1> A = rand(50,50); octave:2> tic;A(:,1) = rand(50,1);toc ans = 0.0082260 octave:3> tic;A = [ rand(50,1), A(:,2:50)];toc ans = 0.00092900 octave:4> > It's almost exactly twice as fast. Sorry Geraint, this is just my > curiosity running amok! :-) > So [...] almost 10 times as fast! Sure... You need to make a test case that takes few seconds, eg.: octave:5> A = ones(5000,5000); octave:6> tic;A(:,1) = rand(5000,1);toc ans = 0.0099300 octave:7> tic;A = [ rand(5000,1), A(:,2:5000)];toc ans = 28.603 > ~Tomer > Regards, Dmitri. ------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. Octave's home on the web: http://www.octave.org How to fund new projects: http://www.octave.org/funding.html Subscription information: http://www.octave.org/archive.html -------------------------------------------------------------