On Fri, May 14, 2010 at 12:42:04AM -0700, Søren Hauberg wrote: > tor, 13 05 2010 kl. 23:09 +0200, skrev Alois Schlögl: > > (i) n(k)+=1; is preferred over n(k)++ for two reasons > > ------------------------------------------------ > > 1) the former is faster > > octave:36> N=1e6; > > octave:37> tic;n=0;for k=1:N, n++;end;toc; > > Elapsed time is 0.48 seconds. > > octave:38> tic;n=0;for k=1:N, n+=1;end;toc; > > Elapsed time is 0.26 seconds. > > Odd. This looks like something that should be improved in Octave. Would > you care to file a bug?
With today's tip, there's no difference: octave:1> N=1e6 N = 1000000 octave:2> tic; n=0; for k = 1:N, n++; end ; toc Elapsed time is 0.39661813 seconds. octave:3> tic; n=0; for k = 1:N, n+=1; end ; toc Elapsed time is 0.40200591 seconds. octave:4> version ans = 3.3.51+ Cheers, Rob ------------------------------------------------------------------------------ _______________________________________________ Octave-dev mailing list Octave-dev@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/octave-dev