From: Binlin Wu on 1 Apr 2010 22:07 If you have enough memory, do the following. a = ones(10000,1000); Then do something like Then compare Case 1: for i = 1:10 b = sqrt(a.^2); end Case 2: b = sqrt(a.^2);b = sqrt(a.^2);b = sqrt(a.^2);b = sqrt(a.^2);b = sqrt(a.^2);b = sqrt(a.^2);b = sqrt(a.^2);b = sqrt(a.^2);b = sqrt(a.^2);b = sqrt(a.^2);% run in one command line Case 3: b = sqrt(a.^2); b = sqrt(a.^2); b = sqrt(a.^2); b = sqrt(a.^2); b = sqrt(a.^2); b = sqrt(a.^2); b = sqrt(a.^2); b = sqrt(a.^2); b = sqrt(a.^2); b = sqrt(a.^2); % run in separate command lines You’ll get 1st and 2nd case run almost with the same speed (maybe different, I can’t tell significant difference.) But 3rd case will be much faster. Why?
From: Binlin Wu on 1 Apr 2010 22:23 Sorry. It's a mistake. I want to close this post. "Binlin Wu" <cunyalen(a)gmail.com> wrote in message <hp3jg9$f54$1(a)fred.mathworks.com>... > If you have enough memory, do the following. > > a = ones(10000,1000); > > Then do something like > > Then compare > > Case 1: > for i = 1:10 > b = sqrt(a.^2); > end > > Case 2: > > b = sqrt(a.^2);b = sqrt(a.^2);b = sqrt(a.^2);b = sqrt(a.^2);b = sqrt(a.^2);b = sqrt(a.^2);b = sqrt(a.^2);b = sqrt(a.^2);b = sqrt(a.^2);b = sqrt(a.^2);% run in one command line > > Case 3: > b = sqrt(a.^2); > b = sqrt(a.^2); > b = sqrt(a.^2); > b = sqrt(a.^2); > b = sqrt(a.^2); > b = sqrt(a.^2); > b = sqrt(a.^2); > b = sqrt(a.^2); > b = sqrt(a.^2); > b = sqrt(a.^2); > % run in separate command lines > > You’ll get 1st and 2nd case run almost with the same speed (maybe different, I can’t tell significant difference.) But 3rd case will be much faster. > > Why?
|
Pages: 1 Prev: How to compare the latest model with the old one? Next: GUI connection |