very different results R2015a and R2015B simple for loop
1 view (last 30 days)
Show older comments
Marinus
on 22 Feb 2016
Commented: Walter Roberson
on 23 Feb 2016
I have a simple piece of code that computes pi using monte carlo method (it's for a matlab shortcourse I'm teaching)
function piresult = compute_pi_for_rand_inside(N)
tic;
total_inside=0;
for i=1:N
xcoord=rand(1);
ycoord=rand(1);
if (xcoord^2 + ycoord^2 <= 1)
total_inside=total_inside+1;
end
end
piresult = 4*total_inside/N;
toc
fprintf('The computed value of pi is %8.7f.\n',piresult);
end
I call this function with N=100000000
on R2015a I get: "Elapsed time is 10.528362 seconds."
However, using R2015b I get: "Elapsed time is 344.462033 seconds."
Why is there such a huge difference in running time? All hardware conditions are exactly the same.
0 Comments
Accepted Answer
Walter Roberson
on 22 Feb 2016
The Just-In-Time engine was rebuilt for R2015b; see http://www.mathworks.com/products/matlab/matlab-execution-engine/
By the way, your code could be vectorized considerably.
2 Comments
Walter Roberson
on 23 Feb 2016
As indicated in that link, there can be some patterns that are made slower. I would not expect anything as bad as you see, so I suggest you open a support case about it.
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!