Created
January 23, 2020 12:20
-
-
Save Liminiens/7560854ee8eca203905498345108ffbc to your computer and use it in GitHub Desktop.
This file contains 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
module Program | |
open System.Collections.Generic | |
open BenchmarkDotNet.Attributes | |
open BenchmarkDotNet.Running | |
[<SimpleJob(launchCount = 3, warmupCount = 3, targetCount = 5)>] | |
[<GcServer(true)>] | |
[<MemoryDiagnoser>] | |
[<MarkdownExporterAttribute.GitHub>] | |
type Benchs() = | |
[<Params(1,1000,1000000)>] | |
member val N = 0 with get, set | |
member __.Indexes = [ | |
for i = 0 to __.N do yield i | |
] | |
member __.Map = | |
Map.ofSeq <| seq { | |
for i = 0 to __.N do | |
yield i, i+1 | |
} | |
member __.Dict = | |
let seq = seq { | |
for i = 0 to __.N do | |
yield KeyValuePair.Create(i, i+1) | |
} | |
new Dictionary<_, _>(seq) | |
[<Benchmark>] | |
[<ArgumentsSource("Indexes")>] | |
member __.mapTest(index) = | |
Map.tryFind index __.Map | |
[<Benchmark>] | |
[<ArgumentsSource("Indexes")>] | |
member __.dictTest(index) = | |
__.Dict.ContainsKey index | |
[<EntryPoint>] | |
let main argv = | |
let summary = BenchmarkRunner.Run<Benchs>(); | |
0 // return an integer exit code | |
``` | |
| Method | N | index | Mean | Error | StdDev | Gen 0 | Gen 1 | Gen 2 | Allocated | | |
|--------- |-------- |------ |-------------------:|-----------------:|-----------------:|-----------:|----------:|----------:|------------:| | |
| mapTest | 1 | 0 | 242.4 ns | 41.02 ns | 38.37 ns | 0.0100 | - | - | 392 B | | |
| dictTest | 1 | 0 | 209.2 ns | 11.60 ns | 10.85 ns | 0.0098 | - | - | 392 B | | |
| mapTest | 1000 | 0 | 598,627.5 ns | 34,521.99 ns | 32,291.89 ns | 12.6953 | - | - | 514304 B | | |
| dictTest | 1000 | 0 | 51,512.4 ns | 1,673.77 ns | 1,565.65 ns | 1.9531 | 0.0610 | - | 73368 B | | |
| mapTest | 1000000 | 0 | 1,379,134,146.7 ns | 64,264,994.87 ns | 60,113,516.07 ns | 25000.0000 | 2000.0000 | 1000.0000 | 993666848 B | | |
| dictTest | 1000000 | 0 | 61,881,864.2 ns | 2,370,891.23 ns | 2,217,733.12 ns | 375.0000 | 375.0000 | 375.0000 | 53889410 B | | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment