generated from Nexus-Mods/NexusMods.App.Template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a few benchmarks and some quick tests with AVX2 lookups
- Loading branch information
Showing
4 changed files
with
101 additions
and
4 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
benchmarks/NexusMods.MnemonicDB.Benchmarks/Benchmarks/IndexSegmentABenchmarks.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,48 @@ | ||
using System; | ||
using BenchmarkDotNet.Attributes; | ||
using NexusMods.MnemonicDB.Abstractions; | ||
using NexusMods.MnemonicDB.Abstractions.DatomIterators; | ||
using NexusMods.MnemonicDB.Abstractions.ElementComparers; | ||
using NexusMods.MnemonicDB.Abstractions.IndexSegments; | ||
using NexusMods.MnemonicDB.Abstractions.Internals; | ||
using NexusMods.MnemonicDB.Storage; | ||
|
||
namespace NexusMods.MnemonicDB.Benchmarks.Benchmarks; | ||
|
||
public class IndexSegmentABenchmarks | ||
{ | ||
private readonly IndexSegment _index; | ||
|
||
public IndexSegmentABenchmarks() | ||
{ | ||
var registry = new AttributeRegistry([]); | ||
using var builder = new IndexSegmentBuilder(registry); | ||
|
||
for (int a = 1; a < 100; a++) | ||
{ | ||
var prefix = new KeyPrefix(EntityId.From(42), AttributeId.From((ushort)a), TxId.From(42), false, | ||
ValueTags.Null); | ||
builder.Add(new Datom(prefix, ReadOnlyMemory<byte>.Empty, registry)); | ||
} | ||
|
||
_index = builder.Build(); | ||
} | ||
|
||
[Params(1, 2, 3, 4, 5, 20, 30, 50, 99)] | ||
public int ToFind { get; set; } | ||
|
||
[Benchmark] | ||
public int FindLinear() | ||
{ | ||
var find = AttributeId.From((ushort)ToFind); | ||
for (var i = 0; i < _index.Count; i++) | ||
{ | ||
var datom = _index[i]; | ||
if (datom.A == find) | ||
return i; | ||
} | ||
return -1; | ||
} | ||
|
||
|
||
} |
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