Created
July 22, 2024 13:11
-
-
Save espio999/3b4456e74557d331b195c45f064121d3 to your computer and use it in GitHub Desktop.
Performance comparison of Fibonacci number in F#
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#load "fibonacci.fsx" | |
open fibonacci | |
open System.Diagnostics | |
let loop_start = 0 | |
let loop_end = 40 | |
let testloop fn = | |
let sw = new Stopwatch() | |
sw.Restart() | |
for i in loop_start .. loop_end do fn i |> printf "%A " | |
sw.Stop() | |
sw.ToString() |> printfn "\n%s" | |
printfn "%s" ("\n" + "recursion") | |
testloop fib | |
printfn "%s" ("\n" + "memoization") | |
testloop fib_memo | |
printfn "%s" ("\n" + "tail rec") | |
testloop fib_tail_recursion |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment