Created
July 27, 2016 01:26
-
-
Save liboz/f992c00393cce1b79c0ec85330e79176 to your computer and use it in GitHub Desktop.
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
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