Looking back at our Fibonnaci examples the Scala compiler offers one big performance boost when using recursion. The only condition is that you use tail recursion. What this basically means is that the last expression in your recursive method is a call to itself.
Below follows a refactored recursive implementation which performs almost as fast as the non-recursive implementation.
No comments:
Post a Comment