Profiler: time spend at while END statement

10 次查看(过去 30 天)
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 个评论
Bruno Luong
Bruno Luong 2022-3-29
编辑:Bruno Luong 2022-3-29
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

请先登录,再进行评论。

回答(1 个)

Jan
Jan 2022-3-29
编辑:Jan 2022-3-29
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.

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by