Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SlottedArrayBenchmarks.Hash_collisions uses a fixed size to make it comparable #347

Merged
merged 2 commits into from
Jun 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/Paprika.Benchmarks/SlottedArrayBenchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ public class SlottedArrayBenchmarks
private readonly byte[] _writable = new byte[Page.PageSize];
private readonly int _to;

// hash collisions are fixed in size to make them comparable
private readonly byte[] _hashCollisions = new byte[Page.PageSize];
private readonly int _hashCollisionsLength;
private const int HashCollisionsCount = NibblePath.KeccakNibbleCount;
private static readonly byte[] HashCollisionValue = new byte[13];

private readonly byte[] _copy0 = new byte[Page.PageSize];
Expand Down Expand Up @@ -53,11 +54,12 @@ public SlottedArrayBenchmarks()
var zeroes = NibblePath.FromKey(Keccak.Zero);
var hashCollisions = new SlottedArray(_hashCollisions);

_hashCollisionsLength = 0;

while (hashCollisions.TrySet(zeroes.SliceTo(_hashCollisionsLength), HashCollisionValue))
for (var i = 0; i <= HashCollisionsCount; i++)
{
_hashCollisionsLength++;
if (!hashCollisions.TrySet(zeroes.SliceTo(i), HashCollisionValue))
{
throw new Exception($"No place to set hash collision at {i}");
}
}
}

Expand Down Expand Up @@ -155,7 +157,7 @@ public int Hash_collisions()

var length = 0;

for (var i = 0; i < _hashCollisionsLength; i++)
for (var i = 0; i < HashCollisionsCount; i++)
{
if (map.TryGet(zeroes.SliceTo(i), out var value))
{
Expand Down
Loading