Skip to content

Commit

Permalink
Updated benchmark program
Browse files Browse the repository at this point in the history
  • Loading branch information
rickardp committed Feb 15, 2023
1 parent 72a6adb commit 1ea665e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
6 changes: 3 additions & 3 deletions Performance/Deduplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ public class Deduplication
public IUtf8DeduplicatedStringPool Pool;

[Benchmark]
public void DoAdd() => Pool.Add(DataSet[Random.Next(0, DataSet.Length)]);
public PooledUtf8String DoAdd() => Pool.Add(DataSet[Random.Next(0, DataSet.Length)]);

public IEnumerable<string[]> CreateDataSet()
{
foreach (var size in new[] { 10000, 100000, 1000000, 10000000 })
foreach (var size in new[] { 10000, 100000, 1000000 })
{
yield return Enumerable.Range(0, size).Select(_ => RandomString()).ToArray();
}
}

public IEnumerable<IUtf8DeduplicatedStringPool> CreatePools()
=> (new[] { 9, 10, 12, 14, 16 }).Select(bits => StringPool.DeduplicatedUtf8(4096, 1, bits));
=> (new[] { 10, 12, 16 }).Select(bits => StringPool.DeduplicatedUtf8(4096, 1, bits));

internal static string RandomString()
{
Expand Down
19 changes: 19 additions & 0 deletions Performance/Hashing.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using BenchmarkDotNet.Attributes;
using Combination.StringPools;

namespace Performance;

#pragma warning disable CS8618
public class Hashing
{
private static IUtf8DeduplicatedStringPool pool = StringPool.DeduplicatedUtf8(4096, 1, 12);

[ParamsSource(nameof(CreateStrings))]
public PooledUtf8String String;

[Benchmark]
public int Hash() => String.GetHashCode();

public IEnumerable<PooledUtf8String> CreateStrings()
=> new[] { pool.Add("Some ASCII string"), pool.Add("Some ünicöde string") };
}
3 changes: 2 additions & 1 deletion Performance/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
using Combination.StringPools;
using Performance;

var summary = BenchmarkRunner.Run<Deduplication>();
//var summary = BenchmarkRunner.Run<Deduplication>();
var summary = BenchmarkRunner.Run<Hashing>();

#if false
foreach (var sizeMultiple in Enumerable.Range(1, 11))
Expand Down
3 changes: 3 additions & 0 deletions src/Combination.StringPools/Utf8StringPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -487,4 +487,7 @@ internal static bool StringsEqual(ulong a, ulong b)
return aPool.GetStringBytes(aOffset).SequenceEqual(aPool.GetStringBytes(bOffset));
}
}

public override string ToString() =>
$"Utf8StringPool(bits={deduplicationTableBits}, dedup={deduplicationTable is not null}, pages={pages.Count}, used={usedBytes}, added={addedBytes})";
}

0 comments on commit 1ea665e

Please sign in to comment.