Skip to content

Instantly share code, notes, and snippets.

@espio999
Created July 22, 2024 13:11
Show Gist options
  • Save espio999/3b4456e74557d331b195c45f064121d3 to your computer and use it in GitHub Desktop.
Save espio999/3b4456e74557d331b195c45f064121d3 to your computer and use it in GitHub Desktop.
Performance comparison of Fibonacci number in F#
#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