Is recursion preferable over iteration in the multi-core era?

Or say multicore processors process recursion faster than iteration?

Or does it just depend on how one language works on the machine? for example, c makes function calls with high cost, comparing with simple iterations.

I had this question because I once told one of my friends that recursion is not an amazing magic that can speed up programs, and he told me that with multi-core processors, recursion can be faster than iteration.

EDIT:

If we consider the situation that we liked most recursion (data structure, function call) Is it possible that recursion be faster?

EDIT ont Oct 12th:

So how does a multi-core processor work? Are software currently programmed for multi-core processors?

+5
source share
2 answers

There are two ways to look at this problem:

1. Looking exclusively at compiled code, yes, iteration is faster than recursion. This is because recursion adds a function call (= overhead), but iteration does not. However, the general type of recursion is tail recursion: a recursive call is made at the end of the function. This is always optimized for iteration by compilers. So in this case it does not matter. Ergo: in some cases, recursion is slower, but it is never faster.

2. , ( , .) , ( , ). , , , , .

+1

, , . , .

0

All Articles