Fibonacci

See Wikibook article.

1. Recursive function based on the definition of the Fibonacci sequence

This follows the mathematic definition of the Fibonacci series. It looks pretty much the same in every language. Top-down, goal-oriented, close to the mathematical definition and but requiring repeated re-evaluations of intermediate values. Time complexity is O(2^n). This algorithm is also unable to take advantage of tail-recursion optimisation. Performance could be greatly improved by memoization ie storing the intermediate values but AFAIK only MarkLogic's version of the XQuery 3.1 construct map supports mutable maps.

2. Recursive function using switch expression

Recursive function with then-else replaced with switch

3. Iterative function written in tail recursive form.

Two functions - a private function for the recursion and a public to initiate the call. They have the same name but different numbers of parameters. This form allows tail-recursion optimisation but the biggest advantage is that it is O(n).

4.

Example script to graph the performance of the two algorithms using Google chart API