|
From: | Rob Mahurin |
Subject: | Re: Performance optimization (allocation inside a for loop) |
Date: | Thu, 2 Apr 2009 14:10:43 -0400 |
On Apr 2, 2009, at 1:25 PM, John W. Eaton wrote:
On 2-Apr-2009, Rob Mahurin wrote: | Any idea why (1:n)(1:n) makes a full matrix more quickly than [1:n]? | Just looking at timing, it looks like [] waits for something that ()| () doesn't. I would have expected any difference to go the other way.What do you mean by "more quickly?"
Well, if I do lim = 1e3; n = 1e5; for i = lim:-1:1; tic; retval = (1:n)(1:n); t_paren(i) = toc; endfor for i = lim:-1:1; tic; retval = [1:n]; t_brack(i) = toc; endfor plot([t_paren; t_brack]')then t_paren is mostly around 7 milliseconds, but t_brack is mostly around 10.5 milliseconds. With n = 1e6 the times are 70 ms and 100 ms or so.
Rob -- Rob Mahurin Department of Physics and Astronomy University of Tennessee 865 207 2594 Knoxville, TN 37996 address@hidden
[Prev in Thread] | Current Thread | [Next in Thread] |