-
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 update benchmark add update method which updates only if the valu…
…e hasnt changed
- Loading branch information
Showing
7 changed files
with
289 additions
and
87 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
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
116 changes: 116 additions & 0 deletions
116
benchmarks/Faster.Map.Concurrent.Benchmark/UpdateBenchmark.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,116 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
using BenchmarkDotNet.Attributes; | ||
using Faster.Map.DenseMap; | ||
using Faster.Map.QuadMap; | ||
using Faster.Map.RobinHoodMap; | ||
|
||
namespace Faster.Map.Concurrent.Benchmark | ||
{ | ||
[MarkdownExporterAttribute.GitHub] | ||
[MemoryDiagnoser] | ||
public class UpdateBenchmark | ||
{ | ||
private CMap<uint, uint> _map; | ||
private System.Collections.Concurrent.ConcurrentDictionary<uint, uint> _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<uint, uint>(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<uint, uint>(NumberOfThreads, 1000000); | ||
|
||
} | ||
|
||
|
||
[Benchmark] | ||
public void NonBlocking() | ||
{ | ||
int numKeys = 1000000; | ||
int segmentSize = numKeys / NumberOfThreads; | ||
|
||
Parallel.For(0, NumberOfThreads, threadIndex => | ||
{ | ||
int start = threadIndex * segmentSize; | ||
int end = (threadIndex == NumberOfThreads - 1) ? numKeys : start + segmentSize; | ||
|
||
for (uint i = (uint)start; i < end; i++) | ||
{ | ||
var key = keys[i]; | ||
_nonBlocking[key] = 0; | ||
} | ||
}); | ||
} | ||
|
||
[Benchmark] | ||
public void CMap() | ||
{ | ||
int numKeys = 1000000; | ||
int segmentSize = numKeys / NumberOfThreads; | ||
|
||
Parallel.For(0, NumberOfThreads, threadIndex => | ||
{ | ||
int start = threadIndex * segmentSize; | ||
int end = (threadIndex == NumberOfThreads - 1) ? numKeys : start + segmentSize; | ||
|
||
for (uint i = (uint)start; i < end; i++) | ||
{ | ||
var key = keys[i]; | ||
_map.Update(key, 0); | ||
} | ||
}); | ||
} | ||
|
||
[Benchmark] | ||
public void ConcurrentDictionary() | ||
{ | ||
int numKeys = 1000000; | ||
int segmentSize = numKeys / NumberOfThreads; | ||
|
||
Parallel.For(0, NumberOfThreads, threadIndex => | ||
{ | ||
int start = threadIndex * segmentSize; | ||
int end = (threadIndex == NumberOfThreads - 1) ? numKeys : start + segmentSize; | ||
|
||
for (uint i = (uint)start; i < end; i++) | ||
{ | ||
var key = keys[i]; | ||
_concurrentMap[key] = 0; | ||
} | ||
}); | ||
} | ||
|
||
|
||
} | ||
} |
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
Oops, something went wrong.