-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
949 additions
and
95 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
using System.Runtime.InteropServices; | ||
using BenchmarkDotNet.Attributes; | ||
using Paprika.Data; | ||
using Paprika.Store; | ||
|
||
namespace Paprika.Benchmarks; | ||
|
||
[DisassemblyDiagnoser] | ||
[MemoryDiagnoser] | ||
public class BitMapFilterBenchmarks | ||
{ | ||
private readonly Page[] _pages1A = AlignedAlloc(1); | ||
private readonly Page[] _pages1B = AlignedAlloc(1); | ||
|
||
private readonly Page[] _pages2A = AlignedAlloc(2); | ||
private readonly Page[] _pages2B = AlignedAlloc(2); | ||
|
||
private readonly Page[] _pages16A = AlignedAlloc(128); | ||
private readonly Page[] _pages16B = AlignedAlloc(128); | ||
|
||
[Benchmark(OperationsPerInvoke = 4)] | ||
public void Or_BitMapFilter_Of1() | ||
{ | ||
var a = new BitMapFilter<BitMapFilter.Of1>(new BitMapFilter.Of1(_pages1A[0])); | ||
var b = new BitMapFilter<BitMapFilter.Of1>(new BitMapFilter.Of1(_pages1B[0])); | ||
|
||
a.OrWith(b); | ||
a.OrWith(b); | ||
a.OrWith(b); | ||
a.OrWith(b); | ||
} | ||
|
||
[Benchmark(OperationsPerInvoke = 4)] | ||
public void Or_BitMapFilter_Of2() | ||
{ | ||
var a = new BitMapFilter<BitMapFilter.Of2>(new BitMapFilter.Of2(_pages2A[0], _pages2A[1])); | ||
var b = new BitMapFilter<BitMapFilter.Of2>(new BitMapFilter.Of2(_pages2B[0], _pages2B[1])); | ||
|
||
a.OrWith(b); | ||
a.OrWith(b); | ||
a.OrWith(b); | ||
a.OrWith(b); | ||
} | ||
|
||
[Benchmark(OperationsPerInvoke = 4)] | ||
public void Or_BitMapFilter_OfN_128() | ||
{ | ||
var a = new BitMapFilter<BitMapFilter.OfN>(new BitMapFilter.OfN(_pages16A)); | ||
var b = new BitMapFilter<BitMapFilter.OfN>(new BitMapFilter.OfN(_pages16B)); | ||
|
||
a.OrWith(b); | ||
a.OrWith(b); | ||
a.OrWith(b); | ||
a.OrWith(b); | ||
} | ||
|
||
[Benchmark(OperationsPerInvoke = 4)] | ||
public int MayContainAny_BitMapFilter_OfN_128() | ||
{ | ||
var a = new BitMapFilter<BitMapFilter.OfN>(new BitMapFilter.OfN(_pages16A)); | ||
|
||
return (a.MayContainAny(13, 17) ? 1 : 0) + | ||
(a.MayContainAny(2342, 2345) ? 1 : 0) + | ||
(a.MayContainAny(3453453, 8789345) ? 1 : 0) + | ||
(a.MayContainAny(2346345, 432509) ? 1 : 0); | ||
} | ||
|
||
private static unsafe Page[] AlignedAlloc(int pageCount) | ||
{ | ||
var pages = new Page[pageCount]; | ||
|
||
for (int i = 0; i < pageCount; i++) | ||
{ | ||
pages[i] = new Page((byte*)NativeMemory.AlignedAlloc(Page.PageSize, Page.PageSize)); | ||
|
||
// make data more interesting | ||
pages[i].Span.Fill((byte)(1 << (i & 7))); | ||
} | ||
|
||
return pages; | ||
} | ||
} |
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,75 @@ | ||
using FluentAssertions; | ||
using Paprika.Chain; | ||
using Paprika.Data; | ||
|
||
namespace Paprika.Tests.Data; | ||
|
||
public abstract class BitMapFilterTests<TAccessor> : IDisposable | ||
where TAccessor : struct, BitMapFilter.IAccessor<TAccessor> | ||
{ | ||
private readonly BufferPool _pool = new(32); | ||
|
||
protected abstract BitMapFilter<TAccessor> Build(BufferPool pool); | ||
|
||
[Test] | ||
public void Non_colliding_set() | ||
{ | ||
var filter = Build(_pool); | ||
|
||
var count = (ulong)filter.BucketCount; | ||
|
||
for (ulong i = 0; i < count; i++) | ||
{ | ||
filter[i].Should().BeFalse(); | ||
filter[i] = true; | ||
filter[i].Should().BeTrue(); | ||
} | ||
|
||
filter.Return(_pool); | ||
} | ||
|
||
[Test] | ||
public void Or_with() | ||
{ | ||
var filter1 = Build(_pool); | ||
var filter2 = Build(_pool); | ||
|
||
const ulong v1 = 1; | ||
const ulong v2 = 4213798855897314219; | ||
|
||
filter1.Add(v1); | ||
filter2.Add(v2); | ||
|
||
filter1.OrWith(filter2); | ||
|
||
filter1.MayContain(v1).Should().BeTrue(); | ||
filter1.MayContain(v2).Should().BeTrue(); | ||
filter1.MayContainAny(v1, v2).Should().BeTrue(); | ||
|
||
filter1.Return(_pool); | ||
filter2.Return(_pool); | ||
} | ||
|
||
public void Dispose() => _pool.Dispose(); | ||
} | ||
|
||
[TestFixture] | ||
public class BitMapFilterTestsOf1 : BitMapFilterTests<BitMapFilter.Of1> | ||
{ | ||
protected override BitMapFilter<BitMapFilter.Of1> Build(BufferPool pool) => BitMapFilter.CreateOf1(pool); | ||
} | ||
|
||
[TestFixture] | ||
public class BitMapFilterTestsOf2 : BitMapFilterTests<BitMapFilter.Of2> | ||
{ | ||
protected override BitMapFilter<BitMapFilter.Of2> Build(BufferPool pool) => BitMapFilter.CreateOf2(pool); | ||
} | ||
|
||
[TestFixture] | ||
public class BitMapFilterTestsOf4 : BitMapFilterTests<BitMapFilter.OfN> | ||
{ | ||
protected override BitMapFilter<BitMapFilter.OfN> Build(BufferPool pool) => BitMapFilter.CreateOfN(pool, 4); | ||
} | ||
|
||
|
||
|
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,27 @@ | ||
using System.Runtime.InteropServices; | ||
using FluentAssertions; | ||
using Paprika.Data; | ||
using Paprika.Store; | ||
|
||
namespace Paprika.Tests.Data; | ||
|
||
public class PageExtensionsTests | ||
{ | ||
[Test] | ||
public void Or_with() | ||
{ | ||
var page0 = Page.DevOnlyNativeAlloc(); | ||
page0.Clear(); | ||
|
||
var page1 = Page.DevOnlyNativeAlloc(); | ||
const byte fill = 0xFF; | ||
page1.Span.Fill(fill); // fill whole page with FFFFF | ||
|
||
const int notFound = -1; | ||
page0.Span.IndexOfAnyExcept((byte)0).Should().Be(notFound); | ||
|
||
page0.OrWith(page1); | ||
|
||
page0.Span.IndexOfAnyExcept(fill).Should().Be(notFound); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using FluentAssertions; | ||
using Paprika.Store; | ||
|
||
namespace Paprika.Tests.Store; | ||
|
||
public class DbAddressSetTests | ||
{ | ||
[Test] | ||
public void Dummy() | ||
{ | ||
const uint max = 1000; | ||
|
||
var set = new DbAddressSet(DbAddress.Page(max)); | ||
|
||
for (uint i = 0; i < max; i++) | ||
{ | ||
var addr = DbAddress.Page(i); | ||
set[addr].Should().BeTrue(); | ||
set[addr] = false; | ||
} | ||
|
||
for (uint i = 0; i < max; i++) | ||
{ | ||
var addr = DbAddress.Page(i); | ||
set[addr].Should().BeFalse(); | ||
} | ||
} | ||
|
||
[Test] | ||
public void Set_enumeration() | ||
{ | ||
const uint max = 5; | ||
var set = new DbAddressSet(DbAddress.Page(max)); | ||
|
||
set[DbAddress.Page(0)] = false; | ||
set[DbAddress.Page(2)] = false; | ||
set[DbAddress.Page(4)] = false; | ||
|
||
set.EnumerateSet().ToArray().Should().BeEquivalentTo([DbAddress.Page(1), DbAddress.Page(3)]); | ||
} | ||
} |
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.