-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Closed
Description
I have implemented it based on the sample app available here
<Project Sdk="FSharp.NET.Sdk;Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp1.1</TargetFramework>
<AssemblyTitle>BenchmarkDotNet.Samples.FSharp.Core</AssemblyTitle>
<AssemblyName>BenchmarkDotNet.Samples.FSharp.Core</AssemblyName>
<PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<Compile Include="Program.fs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="FSharp.NET.Sdk" Version="1.0.*" PrivateAssets="All" />
<PackageReference Include="FSharp.Core" Version="4.1.*" />
<PackageReference Include="BenchmarkDotNet" Version="0.10.2.341" />
</ItemGroup>
</Project>module Program
open System
open System.IO
open System.Collections.Concurrent
open BenchmarkDotNet.Attributes
open BenchmarkDotNet.Running
let getStrings len = Array.init len (fun _ -> Path.GetRandomFileName())
let lookup arr (dict:ConcurrentDictionary<string,bool>) =
arr |> Array.iteri(fun idx elm ->
let mutable b = dict.[elm]
b <- dict.[arr.[0]])
type StringKeyComparison () =
let mutable arr : string [] = [||]
let dict1 = ConcurrentDictionary<_,_>()
let dict2 = ConcurrentDictionary<_,_>(StringComparer.Ordinal)
[<Params (100, 500, 1000, 2000)>]
member val public DictSize = 0 with get, set
[<Setup>]
member self.SetupData() =
dict1.Clear(); dict2.Clear()
arr <- getStrings self.DictSize
arr |> Array.iter (fun x -> dict1.[x] <- true ; dict2.[x] <- true)
[<Benchmark>]
member self.StandardLookup () = lookup arr dict1
[<Benchmark>]
member self.OrdinalLookup () = lookup arr dict2
let defaultSwitch () = BenchmarkSwitcher [| typeof<StringKeyComparison> |]
[<EntryPoint>]
let Main args =
let summary = defaultSwitch().Run args
0Then:
dotnet restore
dotnet run -c Release
neoeinstein