Profile viewer interface question regarding different runtimes quoted

조회 수: 1 (최근 30일)
Otis
Otis 2021년 3월 31일
답변: Vidhi Agarwal 2024년 2월 19일
I ran a pretty big program (lots of files/functions) with the profiler turned on. On the profile viewer main page it claims that 36.508s was spent in one of the functions, call it A. When I go to the page for that subroutine, it says in the table "Lines where the most time was spent" that 30.345 s was spent on a particular line. That line is a call to another function, call it B. In the table "Children (called functions)" it says that 30.162 s was spent in function B. What is the reason for the difference in these two numbers? Is it overhead spent by function A in calling function B? (Note: The total in both of the aforementioned tables matches the value, 36.508, on the main page.) Thanks times a million in advance!
Bill

답변 (1개)

Vidhi Agarwal
Vidhi Agarwal 2024년 2월 19일
Hi Otis,
I understand that your query is regarding the difference in Lines where the most time was spent” and “Children (called functions)time presented by MATLAB profiler.
The discrepancy between the time reported for the line in function A that calls function B (30.345 seconds) and the time spent within function B itself (30.162 seconds) can be attributed to the overhead involved in calling the function. This overhead may include:
  • Time to invoke the function: The process of setting up the call to function B, which includes preparing the arguments, stack frame, and handling the return address.
  • Profiling overhead: The profiler itself adds some overhead, as it has to record the entry and exit points of the functions being called.
  • Time to return from the function: After function B completes, there is some time spent to clean up and return to function A.
The difference (30.345 - 30.162 = 0.183 seconds) is relatively small compared to the total execution time but is nonetheless significant in profiling. This difference is the additional time spent by function A in managing the call to function B, which is not part of the actual execution time of the code within function B.
In summary, the reason for the difference in these two numbers is indeed the overhead associated with the function call mechanism in MATLAB.

카테고리

Help CenterFile Exchange에서 Performance and Memory에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by