Skip to content

Instantly share code, notes, and snippets.

@wingyplus
Last active November 4, 2020 07:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wingyplus/a237b813150f947bb69d641c0f78aa3b to your computer and use it in GitHub Desktop.
Save wingyplus/a237b813150f947bb69d641c0f78aa3b to your computer and use it in GitHub Desktop.
Benchmark fibonacci on F#
// Learn more about F# at http://fsharp.org
open BenchmarkDotNet.Attributes
open BenchmarkDotNet.Running
let rec fibonacci n =
match n with
| 1 -> 1
| 2 -> 2
| n -> fibonacci (n - 1) + fibonacci (n - 2)
let fibonacci2 n =
[ 1 .. n ] |> List.fold (+) 0
type FibonacciBenchmark() =
[<Params(10, 20, 30)>]
member val n = 0 with get, set
[<Benchmark>]
member self.BenchFibonacci() = fibonacci self.n
[<Benchmark>]
member self.BenchFibonacci2() = fibonacci2 self.n
[<EntryPoint>]
let main _argv =
let _summary =
BenchmarkRunner.Run<FibonacciBenchmark>()
0 // return an integer exit code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment