Reformat / cleanup
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
using System.IO.Compression;
|
||||
using System.Text;
|
||||
using BenchmarkDotNet.Attributes;
|
||||
using BenchmarkDotNet.Configs;
|
||||
using BenchmarkDotNet.Jobs;
|
||||
using System.IO.Compression;
|
||||
using ZB.MOM.WW.CBDD.Bson;
|
||||
using ZB.MOM.WW.CBDD.Core.Collections;
|
||||
using ZB.MOM.WW.CBDD.Core.Compression;
|
||||
@@ -19,36 +19,36 @@ public class CompressionBenchmarks
|
||||
{
|
||||
private const int SeedCount = 300;
|
||||
private const int WorkloadCount = 100;
|
||||
private DocumentCollection<Person> _collection = null!;
|
||||
|
||||
private string _dbPath = string.Empty;
|
||||
|
||||
private Person[] _insertBatch = Array.Empty<Person>();
|
||||
private ObjectId[] _seedIds = Array.Empty<ObjectId>();
|
||||
private StorageEngine _storage = null!;
|
||||
private BenchmarkTransactionHolder _transactionHolder = null!;
|
||||
private string _walPath = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets whether compression is enabled for the benchmark run.
|
||||
/// Gets or sets whether compression is enabled for the benchmark run.
|
||||
/// </summary>
|
||||
[Params(false, true)]
|
||||
public bool EnableCompression { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the compression codec for the benchmark run.
|
||||
/// Gets or sets the compression codec for the benchmark run.
|
||||
/// </summary>
|
||||
[Params(CompressionCodec.Brotli, CompressionCodec.Deflate)]
|
||||
public CompressionCodec Codec { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the compression level for the benchmark run.
|
||||
/// Gets or sets the compression level for the benchmark run.
|
||||
/// </summary>
|
||||
[Params(CompressionLevel.Fastest, CompressionLevel.Optimal)]
|
||||
public CompressionLevel Level { get; set; }
|
||||
|
||||
private string _dbPath = string.Empty;
|
||||
private string _walPath = string.Empty;
|
||||
private StorageEngine _storage = null!;
|
||||
private BenchmarkTransactionHolder _transactionHolder = null!;
|
||||
private DocumentCollection<Person> _collection = null!;
|
||||
|
||||
private Person[] _insertBatch = Array.Empty<Person>();
|
||||
private ObjectId[] _seedIds = Array.Empty<ObjectId>();
|
||||
|
||||
/// <summary>
|
||||
/// Prepares benchmark storage and seed data for each iteration.
|
||||
/// Prepares benchmark storage and seed data for each iteration.
|
||||
/// </summary>
|
||||
[IterationSetup]
|
||||
public void Setup()
|
||||
@@ -73,19 +73,19 @@ public class CompressionBenchmarks
|
||||
_seedIds = new ObjectId[SeedCount];
|
||||
for (var i = 0; i < SeedCount; i++)
|
||||
{
|
||||
var doc = CreatePerson(i, includeLargeBio: true);
|
||||
var doc = CreatePerson(i, true);
|
||||
_seedIds[i] = _collection.Insert(doc);
|
||||
}
|
||||
|
||||
_transactionHolder.CommitAndReset();
|
||||
|
||||
_insertBatch = Enumerable.Range(SeedCount, WorkloadCount)
|
||||
.Select(i => CreatePerson(i, includeLargeBio: true))
|
||||
.Select(i => CreatePerson(i, true))
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Cleans up benchmark resources for each iteration.
|
||||
/// Cleans up benchmark resources for each iteration.
|
||||
/// </summary>
|
||||
[IterationCleanup]
|
||||
public void Cleanup()
|
||||
@@ -98,7 +98,7 @@ public class CompressionBenchmarks
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Benchmarks insert workload performance.
|
||||
/// Benchmarks insert workload performance.
|
||||
/// </summary>
|
||||
[Benchmark(Baseline = true)]
|
||||
[BenchmarkCategory("Compression_InsertUpdateRead")]
|
||||
@@ -109,7 +109,7 @@ public class CompressionBenchmarks
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Benchmarks update workload performance.
|
||||
/// Benchmarks update workload performance.
|
||||
/// </summary>
|
||||
[Benchmark]
|
||||
[BenchmarkCategory("Compression_InsertUpdateRead")]
|
||||
@@ -131,7 +131,7 @@ public class CompressionBenchmarks
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Benchmarks read workload performance.
|
||||
/// Benchmarks read workload performance.
|
||||
/// </summary>
|
||||
[Benchmark]
|
||||
[BenchmarkCategory("Compression_InsertUpdateRead")]
|
||||
@@ -141,10 +141,7 @@ public class CompressionBenchmarks
|
||||
for (var i = 0; i < WorkloadCount; i++)
|
||||
{
|
||||
var person = _collection.FindById(_seedIds[i]);
|
||||
if (person != null)
|
||||
{
|
||||
checksum += person.Age;
|
||||
}
|
||||
if (person != null) checksum += person.Age;
|
||||
}
|
||||
|
||||
_transactionHolder.CommitAndReset();
|
||||
@@ -158,7 +155,7 @@ public class CompressionBenchmarks
|
||||
Id = ObjectId.NewObjectId(),
|
||||
FirstName = $"First_{i}",
|
||||
LastName = $"Last_{i}",
|
||||
Age = 20 + (i % 50),
|
||||
Age = 20 + i % 50,
|
||||
Bio = includeLargeBio ? BuildBio(i) : $"bio-{i}",
|
||||
CreatedAt = DateTime.UnixEpoch.AddMinutes(i),
|
||||
Balance = 100 + i,
|
||||
@@ -183,7 +180,7 @@ public class CompressionBenchmarks
|
||||
|
||||
private static string BuildBio(int seed)
|
||||
{
|
||||
var builder = new System.Text.StringBuilder(4500);
|
||||
var builder = new StringBuilder(4500);
|
||||
for (var i = 0; i < 150; i++)
|
||||
{
|
||||
builder.Append("bio-");
|
||||
@@ -195,4 +192,4 @@ public class CompressionBenchmarks
|
||||
|
||||
return builder.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user