Last active
November 4, 2020 07:22
-
-
Save wingyplus/a237b813150f947bb69d641c0f78aa3b to your computer and use it in GitHub Desktop.
Benchmark fibonacci on 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
// 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