Skip to content

Instantly share code, notes, and snippets.

@liboz
Last active July 25, 2016 21:34
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/c0671b5e0ac855e26eef2a856d0f4547 to your computer and use it in GitHub Desktop.
Save liboz/c0671b5e0ac855e26eef2a856d0f4547 to your computer and use it in GitHub Desktop.
open BenchmarkDotNet.Running
open BenchmarkDotNet.Attributes
open BenchmarkDotNet.Configs
open BenchmarkDotNet.Diagnostics.Windows
let pairwiseOriginal (list: 'T list) =
let array = List.toArray list
if array.Length < 2 then [] else
List.init (array.Length-1) (fun i -> array.[i],array.[i+1])
type pairwise () =
[<Params(10, 100, 10000, 1000000)>]
member val public count = 0 with get, set
[<Benchmark>]
member this.pairwise () =
List.pairwise [1..this.count]
[<Benchmark>]
member this.pairwiseOriginal () =
pairwiseOriginal [1..this.count]
[<Benchmark>]
member this.pairwiseString () =
List.pairwise [for i in 1..this.count -> i.ToString() ]
[<Benchmark>]
member this.pairwiseOriginalString () =
pairwiseOriginal [for i in 1..this.count -> i.ToString() ]
let [<EntryPoint>] main args =
let config = ManualConfig.Create(DefaultConfig.Instance)
config.Add(new MemoryDiagnoser())
config.Add(new InliningDiagnoser())
BenchmarkRunner.Run<pairwise>(config) |> ignore
0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment