Why does the same code run 50 times faster in 2008b than in 2012a?

Hi,
I'm runing a simple Monte Carlo loop, using the exact same code, in Matlab R2008b and it takes 29 seconds to do 30,000 iterations, while the same thing in Matlab R2012 a takes 26 minutes.
There is nothing fancy in the loop, I just generate a multivariate randome number and then do the monte carlo simulations (see code below). My code calls a function (psimat) that just reorganizes the data. I just can't understand the huge difference in performance, and it's not the PC, I'm running both on a server.
Any ideas?
Thank you,
Sebastian
for num = 1:monte; % 'monte' times of iterations
smpi_rnd = mvnrnd(smpi,kron(omega,iQ)/nobs); %Multivar. N random number
pi_rnd = reshape(smpi_rnd,K*p+dis*(q+1),K);
psi_rnd = psimat(p,q,K,dis,st,pi_rnd);
% Store mean responses
for i = 1:dis
for j = 1:st+1
mr_rnd(j+(i-1)*(st+1),num) = psi_rnd(K*j,i);
end;
end;
% Store cumulative effects
for i = 1:dis
ce(i,num) = sum(mr_rnd(1+(i-1)*(st+1):4+(i-1)*(st+1),num));
end;
end; % End of Monte Carlo loop

6 件のコメント

Oleg Komarov
Oleg Komarov 2012 年 9 月 11 日
編集済み: Oleg Komarov 2012 年 9 月 11 日
Profile the code and check if there is a bottleneck in the execution on the 2012a. For example, what is psimat()? And, are you sure you're using the same psimat()?
Sean de Wolski
Sean de Wolski 2012 年 9 月 11 日
32bit v. 64bit MATLAB?
Matt Fig
Matt Fig 2012 年 9 月 11 日
Is one a function and the other a script?
Walter Roberson
Walter Roberson 2012 年 9 月 11 日
We've seen some reports of this having to do with 64 bit MATLAB on i5 and i7 processors. I seem to recall the reports were more about R2011b, but I would have to check that.
Jan
Jan 2012 年 9 月 11 日
@Walter: Are there explanations of this effect, or even workarounds? If you do not know any, does TMW do?
per isakson
per isakson 2012 年 9 月 11 日
Sebastian,
Would it be possible for you to provide a piece of code, with which we could try to reproduce your findings?

サインインしてコメントする。

 採用された回答

Ryan G
Ryan G 2012 年 9 月 26 日

0 投票

In general you should expect some minor slowdown between versions for the same code on the same machine with a new version of MATLAB. This is because of added features, maybe some error checking, who knows. However, 26 minutes is a huge slowdown that would be unexpected.. I would also suggest you utilize the MATLAB Profiler to determine where the slowdown occurs.
To speed this up from there you can use PARFOR. See examples below:

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by