Reformat / cleanup
All checks were successful
NuGet Publish / build-and-pack (push) Successful in 46s
NuGet Publish / publish-to-gitea (push) Successful in 56s

This commit is contained in:
Joseph Doherty
2026-02-21 08:10:36 -05:00
parent 4c6aaa5a3f
commit a70d8befae
176 changed files with 50555 additions and 49587 deletions

View File

@@ -1,18 +1,13 @@
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Jobs;
using ZB.MOM.WW.CBDD.Bson;
using ZB.MOM.WW.CBDD.Core;
using ZB.MOM.WW.CBDD.Core.Collections;
using ZB.MOM.WW.CBDD.Core.Storage;
using ZB.MOM.WW.CBDD.Core.Transactions;
using Microsoft.Extensions.Logging;
using Serilog.Context;
using System.IO;
using ZB.MOM.WW.CBDD.Bson;
using ZB.MOM.WW.CBDD.Core.Collections;
using ZB.MOM.WW.CBDD.Core.Storage;
namespace ZB.MOM.WW.CBDD.Tests.Benchmark;
[InProcess]
[MemoryDiagnoser]
[GroupBenchmarksBy(BenchmarkLogicalGroupRule.ByCategory)]
@@ -23,33 +18,30 @@ public class InsertBenchmarks
private const int BatchSize = 1000;
private static readonly ILogger Logger = Logging.CreateLogger<InsertBenchmarks>();
private Person[] _batchData = Array.Empty<Person>();
private DocumentCollection<Person>? _collection;
private string _docDbPath = "";
private string _docDbWalPath = "";
private Person? _singlePerson;
private StorageEngine? _storage = null;
private BenchmarkTransactionHolder? _transactionHolder = null;
private DocumentCollection<Person>? _collection = null;
private Person[] _batchData = Array.Empty<Person>();
private Person? _singlePerson = null;
private StorageEngine? _storage;
private BenchmarkTransactionHolder? _transactionHolder;
/// <summary>
/// Tests setup.
/// Tests setup.
/// </summary>
[GlobalSetup]
public void Setup()
{
var temp = AppContext.BaseDirectory;
string temp = AppContext.BaseDirectory;
var id = Guid.NewGuid().ToString("N");
_docDbPath = Path.Combine(temp, $"bench_docdb_{id}.db");
_docDbWalPath = Path.ChangeExtension(_docDbPath, ".wal");
_singlePerson = CreatePerson(0);
_batchData = new Person[BatchSize];
for (int i = 0; i < BatchSize; i++)
{
_batchData[i] = CreatePerson(i);
}
for (var i = 0; i < BatchSize; i++) _batchData[i] = CreatePerson(i);
}
private Person CreatePerson(int i)
@@ -59,7 +51,7 @@ public class InsertBenchmarks
Id = ObjectId.NewObjectId(),
FirstName = $"First_{i}",
LastName = $"Last_{i}",
Age = 20 + (i % 50),
Age = 20 + i % 50,
Bio = null, // Removed large payload to focus on structure
CreatedAt = DateTime.UtcNow,
Balance = 1000.50m * (i + 1),
@@ -72,8 +64,7 @@ public class InsertBenchmarks
};
// Add 10 work history items to stress structure traversal
for (int j = 0; j < 10; j++)
{
for (var j = 0; j < 10; j++)
p.EmploymentHistory.Add(new WorkHistory
{
CompanyName = $"TechCorp_{i}_{j}",
@@ -81,13 +72,12 @@ public class InsertBenchmarks
DurationYears = j,
Tags = new List<string> { "C#", "BSON", "Performance", "Database", "Complex" }
});
}
return p;
}
/// <summary>
/// Tests iteration setup.
/// Tests iteration setup.
/// </summary>
[IterationSetup]
public void IterationSetup()
@@ -98,7 +88,7 @@ public class InsertBenchmarks
}
/// <summary>
/// Tests cleanup.
/// Tests cleanup.
/// </summary>
[IterationCleanup]
public void Cleanup()
@@ -111,7 +101,7 @@ public class InsertBenchmarks
_storage?.Dispose();
_storage = null;
System.Threading.Thread.Sleep(100);
Thread.Sleep(100);
if (File.Exists(_docDbPath)) File.Delete(_docDbPath);
if (File.Exists(_docDbWalPath)) File.Delete(_docDbWalPath);
@@ -125,7 +115,7 @@ public class InsertBenchmarks
// --- Benchmarks ---
/// <summary>
/// Tests document db insert single.
/// Tests document db insert single.
/// </summary>
[Benchmark(Baseline = true, Description = "CBDD Single Insert")]
[BenchmarkCategory("Insert_Single")]
@@ -136,7 +126,7 @@ public class InsertBenchmarks
}
/// <summary>
/// Tests document db insert batch.
/// Tests document db insert batch.
/// </summary>
[Benchmark(Description = "CBDD Batch Insert (1000 items, 1 Txn)")]
[BenchmarkCategory("Insert_Batch")]
@@ -145,4 +135,4 @@ public class InsertBenchmarks
_collection?.InsertBulk(_batchData);
_transactionHolder?.CommitAndReset();
}
}
}