Profiler: time spend at while END statement

9 views (last 30 days)
Bruno Luong
Bruno Luong on 29 Mar 2022
Edited: Bruno Luong on 29 Mar 2022
I run a profiler on my code, and it is reported a significant amount of time is at the "end" statement of a while loop (here i, n, pivot are scalar, A, idx are vector and cmp is an anymous function that returns a logical)
How to interpret those times ?
  1 Comment
Bruno Luong
Bruno Luong on 29 Mar 2022
Edited: Bruno Luong on 29 Mar 2022
If you want to reproduce such profiler on your side, please run this
profile on; [A, is] = qsort(rand(1,10000)); profile off; profile viewer
with qsort is functionn found in this thread

Sign in to comment.

Answers (1)

Jan
Jan on 29 Mar 2022
Edited: Jan on 29 Mar 2022
I interprete the displayed "times" as a a general problem of the profiler: Matlab's JIT can reorder commands and find abbreviations for the execution of code. This is essential for the speed of loops.
Unfortunately it is impossible to measure the timings line by line, if the JIT has re-organized the code. My opinion is, that the profiler makes the "end" responsible for some computations, which are moved out of the loop's body. This is equivalent to nonsense.
Measuring the performance of Matlab code is a fragile: The profiler reduces the JIT partially or completely. This is not documented exhaustively, but even if it is, it would be subject to changes between the releases. timeit includes some overhead for the anonymous function, tic/toc is not precise, tic/for k=1:1e6/toc includes overhead of the loop and maybe the JIT removes some work, cputime contains magic artifacts. At the end, the timings depend on the temperature of the room, if the CPU throttles.
In short words: The output of the profiler is not reliable.

Categories

Find more on Programming in Help Center and File Exchange

Tags

Products

Community Treasure Hunt

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

Start Hunting!