how to reduce the time of calling functions

조회 수: 12 (최근 30일)
Qiandong Dong
Qiandong Dong 2019년 11월 23일
답변: jeewan atwal 2019년 11월 23일

채택된 답변

Walter Roberson
Walter Roberson 2019년 11월 23일
2/3 of the time is spent executing obj() which is not a Mathworks supplied function. You should investigate obj() to see how it could be sped up.
1/3 of the time is spent executing squeeze(), which is a Mathworks supplied function. As you are calling it many times in a loop, chances are good that you know which dimensions are expected to be singular, and in that situation there is a fairly strong chance that you can replace the call to squeeze() with a call to reshape() which would be more efficient because it would not need to do tests on the dimensions. The savings are probably not all that high though.

추가 답변 (2개)

jeewan atwal
jeewan atwal 2019년 11월 23일
편집: jeewan atwal 2019년 11월 23일
If you are callng MATLAB default functions, then, you cant do much as MATLAB default functions are very well optimized.
However, If you have created some funtions by yourself, then you need to optimize those functions to speed up the things.
Large For loops make MATLAB scripts slow.
If you have large For loop in the functions scripts, then to avoid those For loops you can use MATLAB vectorisation techinques to speed up things.
Hope this helps
  댓글 수: 5
jeewan atwal
jeewan atwal 2019년 11월 23일
I am not claiming that it is always faster. But at least in my problems, i found it faster than for loop. Could you please share any example where vectorisation was slow compared to for loop.

댓글을 달려면 로그인하십시오.


jeewan atwal
jeewan atwal 2019년 11월 23일
Thank you. I appreciate your efforts for this valuable info.

카테고리

Help CenterFile Exchange에서 Debugging and Analysis에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by