Profiler: time spend at while END statement

조회 수: 9 (최근 30일)
Bruno Luong
Bruno Luong 2022년 3월 29일
편집: Bruno Luong 2022년 3월 29일
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