The old (PreR2015b) JIT was highly optimized for a few simple code situations and fell back to the interpreter when it could do nothing. The new JIT runs all code but is not quite up to the same levels of performance for some simple constructs that the previous JIT could handle well. You happened to find a sweet spot for the old JIT.
The standard rules for making your code run fast still apply. R2015b runs your code faster if it is a function than if it is a script and a simple vectorization gets back most of the performance difference:
for i=1:I
for j=1:J
C(i,j)=sum(A(i,:)'.*B(:,j));
end
end
One of the problems with the previous JIT was it's instability. Try adding rng('default') to the script before creating the test variables (line 4) and look what happens to the time.
I bet somebody can figure out how to do this better, however, this code is much faster then the original and shows what can be done with a bit more involved vectorization:
tic
for j=1:J
C(:,j)=sum(bsxfun(@times,A,B(:,j)'),2);
end
toc
On my machine, which seems quite a bit slower then yours, this takes 3.8 seconds in R2015a and 3 seconds in R2015b.
Best Answer