calculation time in for loop

조회 수: 18 (최근 30일)
yuuki harada
yuuki harada 2020년 7월 30일
댓글: yuuki harada 2020년 7월 31일
For example, when I doubled the number of loops, it is suposed that the computation time also doubled. However the computation time was less than twice.
The computation time for each loop has some variation, but as a whole, the later the loop, the shorter the computation time becomes.
the details of the program can't disclose for a number of reasons, but there's no factor that reduces the computation time which depends on the number of loops.
Is the "for loop" in MATLAB done some process behind the scenes to reduce the computation time?
Also, is there any way to check what kind of calculations are being made internally?

채택된 답변

Adam Danz
Adam Danz 2020년 7월 30일
편집: Adam Danz 2020년 7월 30일
If the computations done within the loops are nearly uniform in their complexity, then it's expected that the speed of each loop will increase (become faster) as the number of iterations increase.
This is because of my friend Justin. Justin Time.
Recent releases of Matlab use Just-in-time (JIT) compilation in all Matlab code [see Matlab execution engine]. From that page,
"The performance benefit of JIT compilation is greatest when MATLAB code is executed additional times and can re-use the compiled code. This happens in common cases such as for-loops or when applications are run additional times in a MATLAB session with at least some of the application’s MATLAB files remaining unmodified between subsequent runs."
For more info on JIT, see Loren Shure's blog post: Run Code Faster With the New MATLAB Execution Engine.
  댓글 수: 1
yuuki harada
yuuki harada 2020년 7월 31일
Thank you for your kind explanation!
I will learn more about JIT.
I had a similar hypothesis, but I couldn't clarify what actually happend.
Thank you once again!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by