-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CMAP a concurrent hashtable (#35)
Add a concurrent hashmap, set targetframework to 9.0 (includes interlocked operations for byte)
- Loading branch information
Showing
174 changed files
with
1,849 additions
and
1,507 deletions.
There are no files selected for viewing
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
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
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
85 changes: 79 additions & 6 deletions
85
benchmarks/Faster.Map.Concurrent.Benchmark/AddBenchmark.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,87 @@ | ||
using System.Collections.Concurrent; | ||
using System.Threading; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
using BenchmarkDotNet.Attributes; | ||
using Faster.Map.Concurrent; | ||
using Faster.Map.DenseMap; | ||
using Faster.Map.QuadMap; | ||
using Faster.Map.RobinHoodMap; | ||
|
||
namespace Faster.Map.Concurrent.Benchmark | ||
{ | ||
[MarkdownExporterAttribute.GitHub] | ||
|
||
[MemoryDiagnoser] | ||
public class AddBenchmark | ||
{ | ||
} | ||
} | ||
private CMap<uint, uint> _map; | ||
private System.Collections.Concurrent.ConcurrentDictionary<int, int> _concurrentMap; | ||
private NonBlocking.ConcurrentDictionary<uint, uint> _nonBlocking; | ||
|
||
[Params(1000000)] | ||
public uint Length { get; set; } | ||
private uint[] keys; | ||
|
||
private const int N = 1000000; // Adjust as needed for your scale | ||
|
||
[Params(1, 8, 16, 32, 64, 128 /*, 256, 512*/)] // Example thread counts to test scalability | ||
public int NumberOfThreads { get; set; } | ||
|
||
[GlobalSetup] | ||
public void Setup() | ||
{ | ||
_map = new CMap<uint, uint>(2000000); | ||
_nonBlocking = new NonBlocking.ConcurrentDictionary<uint, uint>(NumberOfThreads, 2000000); | ||
_concurrentMap = new System.Collections.Concurrent.ConcurrentDictionary<int, int>(NumberOfThreads, 1000000); | ||
|
||
var output = File.ReadAllText("Numbers.txt"); | ||
var splittedOutput = output.Split(','); | ||
|
||
keys = new uint[Length]; | ||
|
||
for (var index = 0; index < Length; index++) | ||
{ | ||
keys[index] = uint.Parse(splittedOutput[index]); | ||
} | ||
} | ||
|
||
[IterationSetup] | ||
public void Clean() | ||
{ | ||
_map = new CMap<uint, uint>(2000000); | ||
_nonBlocking = new NonBlocking.ConcurrentDictionary<uint, uint>(NumberOfThreads, 2000000); | ||
_concurrentMap = new System.Collections.Concurrent.ConcurrentDictionary<int, int>(NumberOfThreads, 1000000); | ||
|
||
} | ||
|
||
|
||
[Benchmark] | ||
public void NonBlocking() | ||
{ | ||
Parallel.For(0, N, new ParallelOptions { MaxDegreeOfParallelism = NumberOfThreads }, i => | ||
{ | ||
var key = keys[i]; | ||
_nonBlocking.TryAdd(key, key); | ||
}); | ||
} | ||
|
||
[Benchmark] | ||
public void CMap() | ||
{ | ||
Parallel.For(0, N, new ParallelOptions { MaxDegreeOfParallelism = NumberOfThreads }, i => | ||
{ | ||
var key = keys[i]; | ||
_map.Emplace(key, key); | ||
}); | ||
} | ||
|
||
[Benchmark] | ||
public void ConcurrentDictionary() | ||
{ | ||
Parallel.For(0, N, new ParallelOptions { MaxDegreeOfParallelism = NumberOfThreads }, i => | ||
{ | ||
_concurrentMap.TryAdd(i, i); | ||
}); | ||
} | ||
|
||
|
||
} | ||
} |
20 changes: 15 additions & 5 deletions
20
benchmarks/Faster.Map.Concurrent.Benchmark/Faster.Map.Concurrent.Benchmark.csproj
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,29 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFrameworks>net8.0</TargetFrameworks> | ||
<TargetFrameworks>net9.0</TargetFrameworks> | ||
<ImplicitUsings>disable</ImplicitUsings> | ||
<Nullable>disable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="BenchmarkDotNet" Version="0.13.2" /> | ||
<PackageReference Include="NonBlocking" Version="2.1.0" /> | ||
<None Remove="Numbers.txt" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\Faster.Map\Faster.Map.csproj" /> | ||
<Content Include="Numbers.txt"> | ||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
</Content> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="BenchmarkDotNet" Version="0.13.12" /> | ||
<PackageReference Include="NonBlocking" Version="2.1.2" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\Faster.Map.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
94 changes: 94 additions & 0 deletions
94
benchmarks/Faster.Map.Concurrent.Benchmark/GetBenchmark.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
using BenchmarkDotNet.Attributes; | ||
using Faster.Map.DenseMap; | ||
using Faster.Map.QuadMap; | ||
using Faster.Map.RobinHoodMap; | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Concurrent; | ||
using System.Collections.Generic; | ||
|
||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Faster.Map.Concurrent.Benchmark | ||
{ | ||
public class GetBenchmark | ||
{ | ||
CMap<uint, uint> _map = new CMap<uint, uint>(); | ||
NonBlocking.ConcurrentDictionary<uint, uint> _dic = new NonBlocking.ConcurrentDictionary<uint, uint>(); | ||
ConcurrentDictionary<uint, uint> _dic2; | ||
|
||
[Params(1000000)] | ||
public uint Length { get; set; } | ||
private uint[] keys; | ||
|
||
|
||
[Params(1, 8, 16, 32, 64, 128)] // Example thread counts to test scalability | ||
public int NumberOfThreads { get; set; } | ||
|
||
|
||
[GlobalSetup] | ||
public void Setup() | ||
{ | ||
_dic2 = new ConcurrentDictionary<uint, uint>(NumberOfThreads, 1); | ||
var output = File.ReadAllText("Numbers.txt"); | ||
var splittedOutput = output.Split(','); | ||
|
||
keys = new uint[Length]; | ||
|
||
for (var index = 0; index < Length; index++) | ||
{ | ||
keys[index] = uint.Parse(splittedOutput[index]); | ||
} | ||
|
||
foreach (var key in keys) | ||
{ | ||
_map.Emplace(key, key); | ||
_dic.TryAdd(key, key); | ||
_dic2.TryAdd(key, key); | ||
} | ||
} | ||
|
||
[Benchmark] | ||
public void ConcurrentDictionary() | ||
{ | ||
Parallel.For(0, NumberOfThreads, i => | ||
{ | ||
for (int j = 0; j < Length; j++) | ||
{ | ||
var key = keys[j]; | ||
_dic2.TryGetValue(key, out _); | ||
} | ||
}); | ||
} | ||
|
||
|
||
[Benchmark] | ||
public void NonBlocking() | ||
{ | ||
Parallel.For(0, NumberOfThreads, i => | ||
{ | ||
for (int j = 0; j < Length; j++) | ||
{ | ||
var key = keys[j]; | ||
_dic.TryGetValue(key, out _); | ||
} | ||
}); | ||
} | ||
|
||
[Benchmark] | ||
public void GetCmapBenchmark() | ||
{ | ||
Parallel.For(0, NumberOfThreads, i => | ||
{ | ||
for (int j = 0; j < Length; j++) | ||
{ | ||
var key = keys[j]; | ||
_map.Get(key, out _); | ||
} | ||
}); | ||
} | ||
} | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
using BenchmarkDotNet.Running; | ||
using BenchmarkDotNet.Configs; | ||
using BenchmarkDotNet.Running; | ||
|
||
namespace Faster.Map.Concurrent.Benchmark | ||
{ | ||
internal class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
BenchmarkRunner.Run<AddBenchmark>(); | ||
{ | ||
BenchmarkRunner.Run<GetBenchmark>(); | ||
} | ||
} | ||
} |
Binary file removed
BIN
-21.5 KB
benchmarks/Faster.Map.Concurrent.Benchmark/bin/Debug/net8.0/BenchmarkDotNet.Annotations.dll
Binary file not shown.
Binary file removed
BIN
-3.56 MB
benchmarks/Faster.Map.Concurrent.Benchmark/bin/Debug/net8.0/BenchmarkDotNet.dll
Binary file not shown.
Binary file removed
BIN
-190 KB
benchmarks/Faster.Map.Concurrent.Benchmark/bin/Debug/net8.0/CommandLine.dll
Binary file not shown.
Binary file removed
BIN
-57.6 KB
benchmarks/Faster.Map.Concurrent.Benchmark/bin/Debug/net8.0/Dia2Lib.dll
Binary file not shown.
Oops, something went wrong.