Fix audit findings for coverage, architecture checks, and XML docs
All checks were successful
NuGet Publish / build-and-pack (push) Successful in 45s
NuGet Publish / publish-to-gitea (push) Successful in 52s

This commit is contained in:
Joseph Doherty
2026-02-20 15:43:25 -05:00
parent 5528806518
commit 3ffd468c79
99 changed files with 23746 additions and 9548 deletions

View File

@@ -1,110 +1,114 @@
using System.Diagnostics;
using System.IO;
using System.Text;
using Microsoft.Extensions.Logging;
using Serilog.Context;
namespace ZB.MOM.WW.CBDD.Tests.Benchmark;
using System.Diagnostics;
using System.IO;
using System.Text;
using Microsoft.Extensions.Logging;
using Serilog.Context;
public class ManualBenchmark
{
private static StringBuilder _log = new();
namespace ZB.MOM.WW.CBDD.Tests.Benchmark;
private static void Log(ILogger logger, string message = "")
{
logger.LogInformation("{Message}", message);
_log.AppendLine(message);
}
public class ManualBenchmark
{
private static StringBuilder _log = new();
private static void Log(ILogger logger, string message = "")
{
logger.LogInformation("{Message}", message);
_log.AppendLine(message);
}
/// <summary>
/// Tests run.
/// </summary>
/// <param name="logger">Logger for benchmark progress and results.</param>
public static void Run(ILogger logger)
{
using var _ = LogContext.PushProperty("Benchmark", nameof(ManualBenchmark));
_log.Clear();
Log(logger, "=== MANUAL BENCHMARK: CBDD ===");
Log(logger, $"Date: {DateTime.Now}");
Log(logger, "Testing: Complex Objects (Nested Documents + Collections)\n");
long batchInsertMs;
long singleInsertMs;
long readByIdMs;
using (LogContext.PushProperty("Phase", "BatchInsert"))
{
Log(logger, "1. Batch Insert (1000 items)");
var insertBench = new InsertBenchmarks();
insertBench.Setup();
insertBench.IterationSetup();
try
{
var sw = Stopwatch.StartNew();
insertBench.DocumentDb_Insert_Batch();
sw.Stop();
batchInsertMs = sw.ElapsedMilliseconds;
Log(logger, $" CBDD InsertBulk (1000): {batchInsertMs} ms");
}
finally
{
insertBench.Cleanup();
}
}
using (LogContext.PushProperty("Phase", "FindById"))
{
Log(logger, "\n2. FindById Performance (1000 operations)");
var readBench = new ReadBenchmarks();
readBench.Setup();
try
{
var sw = Stopwatch.StartNew();
for (int i = 0; i < 1000; i++)
{
readBench.DocumentDb_FindById();
}
sw.Stop();
readByIdMs = sw.ElapsedMilliseconds;
Log(logger, $" CBDD FindById x1000: {readByIdMs} ms ({(double)readByIdMs / 1000:F3} ms/op)");
}
finally
{
readBench.Cleanup();
}
}
using (LogContext.PushProperty("Phase", "SingleInsert"))
{
Log(logger, "\n3. Single Insert");
var insertBench = new InsertBenchmarks();
insertBench.Setup();
insertBench.IterationSetup();
try
{
var sw = Stopwatch.StartNew();
insertBench.DocumentDb_Insert_Single();
sw.Stop();
singleInsertMs = sw.ElapsedMilliseconds;
Log(logger, $" CBDD Single Insert: {singleInsertMs} ms");
}
finally
{
insertBench.Cleanup();
}
}
Log(logger, "\n============================================================================");
Log(logger, "BENCHMARK RESULTS (CBDD ONLY):");
Log(logger, "============================================================================");
Log(logger, $"Batch Insert (1000): {batchInsertMs} ms");
Log(logger, $"FindById x1000: {readByIdMs} ms");
Log(logger, $"Single Insert: {singleInsertMs} ms");
var artifactsDir = Path.Combine(AppContext.BaseDirectory, "BenchmarkDotNet.Artifacts", "results");
if (!Directory.Exists(artifactsDir))
{
Directory.CreateDirectory(artifactsDir);
}
var filePath = Path.Combine(artifactsDir, "manual_report.txt");
File.WriteAllText(filePath, _log.ToString());
logger.LogInformation("Report saved to: {FilePath}", filePath);
}
}
{
using var _ = LogContext.PushProperty("Benchmark", nameof(ManualBenchmark));
_log.Clear();
Log(logger, "=== MANUAL BENCHMARK: CBDD ===");
Log(logger, $"Date: {DateTime.Now}");
Log(logger, "Testing: Complex Objects (Nested Documents + Collections)\n");
long batchInsertMs;
long singleInsertMs;
long readByIdMs;
using (LogContext.PushProperty("Phase", "BatchInsert"))
{
Log(logger, "1. Batch Insert (1000 items)");
var insertBench = new InsertBenchmarks();
insertBench.Setup();
insertBench.IterationSetup();
try
{
var sw = Stopwatch.StartNew();
insertBench.DocumentDb_Insert_Batch();
sw.Stop();
batchInsertMs = sw.ElapsedMilliseconds;
Log(logger, $" CBDD InsertBulk (1000): {batchInsertMs} ms");
}
finally
{
insertBench.Cleanup();
}
}
using (LogContext.PushProperty("Phase", "FindById"))
{
Log(logger, "\n2. FindById Performance (1000 operations)");
var readBench = new ReadBenchmarks();
readBench.Setup();
try
{
var sw = Stopwatch.StartNew();
for (int i = 0; i < 1000; i++)
{
readBench.DocumentDb_FindById();
}
sw.Stop();
readByIdMs = sw.ElapsedMilliseconds;
Log(logger, $" CBDD FindById x1000: {readByIdMs} ms ({(double)readByIdMs / 1000:F3} ms/op)");
}
finally
{
readBench.Cleanup();
}
}
using (LogContext.PushProperty("Phase", "SingleInsert"))
{
Log(logger, "\n3. Single Insert");
var insertBench = new InsertBenchmarks();
insertBench.Setup();
insertBench.IterationSetup();
try
{
var sw = Stopwatch.StartNew();
insertBench.DocumentDb_Insert_Single();
sw.Stop();
singleInsertMs = sw.ElapsedMilliseconds;
Log(logger, $" CBDD Single Insert: {singleInsertMs} ms");
}
finally
{
insertBench.Cleanup();
}
}
Log(logger, "\n============================================================================");
Log(logger, "BENCHMARK RESULTS (CBDD ONLY):");
Log(logger, "============================================================================");
Log(logger, $"Batch Insert (1000): {batchInsertMs} ms");
Log(logger, $"FindById x1000: {readByIdMs} ms");
Log(logger, $"Single Insert: {singleInsertMs} ms");
var artifactsDir = Path.Combine(AppContext.BaseDirectory, "BenchmarkDotNet.Artifacts", "results");
if (!Directory.Exists(artifactsDir))
{
Directory.CreateDirectory(artifactsDir);
}
var filePath = Path.Combine(artifactsDir, "manual_report.txt");
File.WriteAllText(filePath, _log.ToString());
logger.LogInformation("Report saved to: {FilePath}", filePath);
}
}