chore: minor adjustments to benchmarks

This commit is contained in:
Timothy Schenk 2024-02-21 11:56:39 +01:00
parent eb0b81cf59
commit b78c7adf39
Signed by: rainote
SSH key fingerprint: SHA256:pnkNSDwpAnaip00xaZlVFHKKsS7T8UtOomMzvs0yITE

View file

@ -11,10 +11,10 @@ namespace Benchmarks;
[Orderer(SummaryOrderPolicy.FastestToSlowest)]
public class DataCacheBenchmark
{
private ConcurrentDictionary<int, int> _concurrentDictionary;
private Dictionary<int, int> _dictionary;
private HashSet<int> _hashSet;
private ImmutableHashSet<int> _immutableHashSet;
private ConcurrentDictionary<int, int> _concurrentDictionary = null!;
private Dictionary<int, int> _dictionary = null!;
private HashSet<int> _hashSet = null!;
private ImmutableHashSet<int> _immutableHashSet = null!;
[Params(1000, 100000, 1000000)] public int N;
[GlobalSetup]
@ -63,24 +63,24 @@ public class DataCacheBenchmark
[Benchmark]
public void ImmutableHashSetLookup()
{
ParallelEnumerable.Range(0, N).AsParallel().ForAll(i => _immutableHashSet.Contains(i));
ParallelEnumerable.Range(0, N).AsParallel().ForAll(i => { _ = _immutableHashSet.Contains(i); });
}
[Benchmark]
public void HashSetLookup()
{
ParallelEnumerable.Range(0, N).AsParallel().ForAll(i => _hashSet.Contains(i));
ParallelEnumerable.Range(0, N).AsParallel().ForAll(i => { _ = _hashSet.Contains(i); });
}
[Benchmark]
public void DictionaryLookup()
{
ParallelEnumerable.Range(0, N).AsParallel().ForAll(i => _dictionary.ContainsKey(i));
ParallelEnumerable.Range(0, N).AsParallel().ForAll(i => { _ = _dictionary.ContainsKey(i); });
}
[Benchmark]
public void ConcurrentDictionaryLookup()
{
ParallelEnumerable.Range(0, N).AsParallel().ForAll(i => _concurrentDictionary.ContainsKey(i));
ParallelEnumerable.Range(0, N).AsParallel().ForAll(i => { _ = _concurrentDictionary.ContainsKey(i); });
}
}