Profile viewer interface question regarding different runtimes quoted

1 次查看(过去 30 天)
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