|
| 1 | +using BenchmarkDotNet.Attributes; |
| 2 | +using Microsoft.Extensions.DependencyInjection; |
| 3 | +using ModularityKit.Mutator.Abstractions.Audit; |
| 4 | +using ModularityKit.Mutator.Abstractions.Engine; |
| 5 | +using ModularityKit.Mutator.Abstractions.History; |
| 6 | +using ModularityKit.Mutator.Benchmarks.Diagnostics.Support; |
| 7 | + |
| 8 | +namespace ModularityKit.Mutator.Benchmarks.Diagnostics; |
| 9 | + |
| 10 | +/// <summary> |
| 11 | +/// Benchmarks audit, history, and logging-style overhead in the core mutation pipeline. |
| 12 | +/// </summary> |
| 13 | +[BenchmarkCategory("Diagnostics")] |
| 14 | +[MemoryDiagnoser] |
| 15 | +[InProcess] |
| 16 | +public class DiagnosticsOverheadBenchmarks |
| 17 | +{ |
| 18 | + private IMutationEngine _noDiagnosticsEngine = null!; |
| 19 | + private IMutationEngine _auditHistoryEngine = null!; |
| 20 | + private IMutationEngine _combinedDiagnosticsEngine = null!; |
| 21 | + private DiagnosticsState _state = null!; |
| 22 | + private DiagnosticsMutation _mutation = null!; |
| 23 | + |
| 24 | + /// <summary> |
| 25 | + /// Prepares baseline, audit-history, and combined observability benchmark engines. |
| 26 | + /// </summary> |
| 27 | + [GlobalSetup] |
| 28 | + public void Setup() |
| 29 | + { |
| 30 | + _noDiagnosticsEngine = DiagnosticsBenchmarkScenario.BuildEngine( |
| 31 | + services => |
| 32 | + { |
| 33 | + services.AddSingleton<IMutationAuditor, NoOpAuditor>(); |
| 34 | + services.AddSingleton<IMutationHistoryStore, NoOpHistoryStore>(); |
| 35 | + }); |
| 36 | + |
| 37 | + _auditHistoryEngine = DiagnosticsBenchmarkScenario.BuildEngine(); |
| 38 | + |
| 39 | + _combinedDiagnosticsEngine = DiagnosticsBenchmarkScenario.BuildEngine( |
| 40 | + configureEngine: engine => |
| 41 | + { |
| 42 | + engine.RegisterInterceptor(new PassiveBenchmarkInterceptor()); |
| 43 | + engine.RegisterInterceptor(new FormattingLoggingInterceptor()); |
| 44 | + }); |
| 45 | + |
| 46 | + _state = new DiagnosticsState(42, "baseline"); |
| 47 | + _mutation = DiagnosticsBenchmarkScenario.CreateCommitMutation("diagnostics"); |
| 48 | + } |
| 49 | + |
| 50 | + /// <summary> |
| 51 | + /// Measures commit execution with observability paths disabled via no-op audit and history services. |
| 52 | + /// </summary> |
| 53 | + [Benchmark(Baseline = true)] |
| 54 | + public async Task NoDiagnostics_Baseline() |
| 55 | + { |
| 56 | + var result = await _noDiagnosticsEngine.ExecuteAsync(_mutation, _state); |
| 57 | + GC.KeepAlive(result); |
| 58 | + } |
| 59 | + |
| 60 | + /// <summary> |
| 61 | + /// Measures commit execution with the default audit and history capture path enabled. |
| 62 | + /// </summary> |
| 63 | + [Benchmark] |
| 64 | + public async Task AuditHistory_Enabled() |
| 65 | + { |
| 66 | + var result = await _auditHistoryEngine.ExecuteAsync(_mutation, _state); |
| 67 | + GC.KeepAlive(result); |
| 68 | + } |
| 69 | + |
| 70 | + /// <summary> |
| 71 | + /// Measures commit execution with audit/history capture plus interceptor and logging-style formatting enabled. |
| 72 | + /// </summary> |
| 73 | + [Benchmark] |
| 74 | + public async Task CombinedInterceptionAndDiagnostics_Enabled() |
| 75 | + { |
| 76 | + var result = await _combinedDiagnosticsEngine.ExecuteAsync(_mutation, _state); |
| 77 | + GC.KeepAlive(result); |
| 78 | + } |
| 79 | +} |
0 commit comments