MATLAB: Profiler Paradox

for loopoptimizationparadoxparallel computingprofiler

In an attempt to rotate multiple 3×3 matrices I use two approaches. The first is by running a for loop in which I rotate each job separately. The other approach is where setup a sparse block diagonal matrix and rotate once. In order to find out which is most time-efficient I place tic-toc's around each function and I also use Profiler.
Like this:
tic
function1
toc
tic
function2
toc
The paradox: When using Profiler the function2 is faster, when not using Profiler the function1 is faster. Significantly different (I run several times to get average)
I would expect that using Profiler would yield an overall extended runtime, because it measures everything going on, but I certainly wouldn't expect the two functions switch place in speed.

Best Answer

The difference is due to the JIT accelerator that kicks in when using the profiler. Same is if you save the script which calculates the running times and call it from cmd window.
Some useful links:
Oleg
Related Question