+ 1
Which is faster? Recursion or Iteration?
3 ответов
+ 19
Iteration
+ 6
Hello, Terence !
Your performance deteriorates when using recursion, because calling a method in any language involves a lot of preparation: the call code sends the return address, the call parameters, other information about the content, such as the processor registers, can be stored somewhere, and for the return time The called method sends the return value, which is then retrieved by the caller, and any context information that was previously stored will be restored. The difference between the iterative and recursive approach is that these operations are performed.
In terms of implementation, you are really starting to notice the difference when the time required to process the calling context is comparable to the time it takes to execute your method. If your recursive method takes longer to execute, go in a recursive way, because the code is usually more readable and understandable.
+ 1
i think its ITERATION