Skip to content

Instantly share code, notes, and snippets.

@liboz
Created July 27, 2016 01:26
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 liboz/f992c00393cce1b79c0ec85330e79176 to your computer and use it in GitHub Desktop.
Save liboz/f992c00393cce1b79c0ec85330e79176 to your computer and use it in GitHub Desktop.
open BenchmarkDotNet.Running
open BenchmarkDotNet.Attributes
open BenchmarkDotNet.Configs
open BenchmarkDotNet.Diagnostics.Windows
let rec chooseAllAcc f xs acc =
match xs with
| [] -> List.rev acc
| h :: t ->
match f h with
| None -> chooseAllAcc f t acc
| Some x -> chooseAllAcc f t (x::acc)
let chooseOriginal f xs = chooseAllAcc f xs []
type choose () =
[<Params(10, 100, 10000, 1000000)>]
member val public count = 0 with get, set
[<Benchmark>]
member this.choose () =
List.choose (fun i -> if i%2 = 0 then Some i else None) [1..this.count]
[<Benchmark>]
member this.chooseOriginal () =
chooseOriginal (fun i -> if i%2 = 0 then Some i else None) [1..this.count]
let [<EntryPoint>] main args =
let config = ManualConfig.Create(DefaultConfig.Instance)
config.Add(new MemoryDiagnoser())
config.Add(new InliningDiagnoser())
BenchmarkRunner.Run<choose>(config) |> ignore
0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment