Profiler Paradox

3 ビュー (過去 30 日間)
Mads
Mads 2011 年 2 月 16 日
In an attempt to rotate multiple 3x3 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.

採用された回答

Oleg Komarov
Oleg Komarov 2011 年 2 月 16 日
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

その他の回答 (3 件)

Walter Roberson
Walter Roberson 2011 年 2 月 16 日
Some releases have inexplicable longer times for a later call when profiling. See a specific case and some test results here

Derek O'Connor
Derek O'Connor 2011 年 2 月 16 日
In certain cases the profiler is worse than useless -- it is misleading. As you will have noticed, the profiler adds a lot of overhead time. This is noise (not wanted) and it can swamp the execution times of the functions you are interested in.
For me, the only reliable numbers that the profiler produces are the statement counts.
See pages 16 and 17 of my notes which discusses an example similar to yours.
Regards,
Derek O'Connor

Matt Tearle
Matt Tearle 2011 年 3 月 7 日
Profiler isn't really the right tool for (absolute) timing a chunk of code - as has been noted, it adds overhead, plus you have to worry about whether JITing is happening or not, etc etc etc. Use the profiler to find bottlenecks/inefficiencies within a piece of code. Use tic and toc (averaged over multiple runs - +10 Cleve points for knowing to do that!) to compare two functions.

カテゴリ

Help Center および File ExchangeMathematics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by