From help-octave-request at bevo dot che dot wisc dot edu Thu Jan 8 21:06:11 2004 Subject: Ops on matrix in cell array much slower than on bare matrix From: "John W. Eaton" To: gdg at zplane dot com Cc: help-octave at bevo dot che dot wisc dot edu Date: Thu, 8 Jan 2004 21:05:53 -0600 On 8-Jan-2004, Glenn Golden wrote: | # Same thing as above, except using cell array to hold the matrix. Average | # execution time per assignment is around 100 times larger (2.3 ms) than | # above. The slowdown factor is related to the size of the matrix (ysize). | # | y = cell(1,2); | y{1} = zeros(ysize,1); | start = cputime(); | for k = 1:nloops | y{1}(1) = 123.4; y{1} generates a temporary. The temporary value is shared with the original, but a copy is made when you index it for the assignment. If you really need the speed, then workaround is: t = y{1}; y{1} = []; t(1) = 123.4; y{1} = t; Assigning something else to y{1} frees the second reference to the temporary so that no copy is needed for the assignment. You won't see any improvement if you omit that step. I suppose it would be possible for some extra analysis to make this happen automatically, but that is not how things are implemented now. jwe ------------------------------------------------------------- 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 -------------------------------------------------------------