![]() |
|
|||||||
|
|
Thread Tools | Search this Thread | Rate Thread |
|
#1
|
|||
|
|||
Performance comparison between recursive and iterative functionsWhile studying recursion, the classic example of the Fibonacci series was given. Just for giggles, I decided to do it as an iterative function for comparison. What an amazing performance difference! Really makes you wonder when a recursive function is actually useable. Comments?
Here's my code: CPP / C++ / C Code:
Quote:
|
|
#2
|
||||
|
||||
Re: Performance comparison between recursive and iterative functionsRecursion often has other benefits that can make up for lost performance. In particular, the readability and elegance of the code, and maintainability.
If the body of the function is heavy, then the function-call overhead can quickly become insignificant. If the function body is small and light, as in your Fibonacci example, then the overhead for the recursive calls can be significant in comparison. Matthew __________________
I was born not knowing and have only had a little time to change that here and there. -- Richard P. Feynman Boris Podolsky: James! How's the rat business? James Moreland: Well, actually it's mostly students I'm experimenting on now. Kurt Gödel: My God, the mazes must be enormous. |
Recent GIDBlog
Writing a book by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The