diff --git a/README.md b/README.md index 69d23ed..cd8c959 100644 --- a/README.md +++ b/README.md @@ -470,6 +470,8 @@ BenchmarkDotNet guidance is documented in [docs/guides/benchmarks.md](docs/guide | Cache-Aside | Execution | 216.50 ns | 1,048 B | 208.60 ns | 1,048 B | Same allocation; generated was slightly faster for the miss-then-hit workflow. | | Data Mapper | Construction | 40.56 ns | 288 B | 12.87 ns | 112 B | Generated reduced construction time and allocation in this microbenchmark. | | Data Mapper | Execution | 188.09 ns | 1,104 B | 97.71 ns | 672 B | Generated reduced execution time and allocation for the map-store-load workflow. | +| Domain Event | Construction | 199.5 ns | 1.34 KB | 157.6 ns | 1.04 KB | Generated reduced construction time and allocation in this microbenchmark. | +| Domain Event | Execution | 367.2 ns | 1.77 KB | 346.4 ns | 1.55 KB | Generated reduced execution time and allocation for the order-placed dispatch workflow. | | Leader Election | Construction | 14.28 ns | 104 B | 15.91 ns | 104 B | Same allocation; fluent was slightly faster in this microbenchmark. | | Leader Election | Execution | 43.62 ns | 360 B | 144.37 ns | 312 B | Generated allocated about 13% less memory, while fluent was faster in this path. | | Materialized View | Construction | 140.9 ns | 1.05 KB | 147.4 ns | 1.05 KB | Same allocation; fluent was slightly faster in this microbenchmark. | @@ -488,10 +490,14 @@ BenchmarkDotNet guidance is documented in [docs/guides/benchmarks.md](docs/guide | Scheduler Agent Supervisor | Execution | 177.46 ns | 1,304 B | 180.14 ns | 1,304 B | Effectively equivalent for this scenario. | | Service Activator | Construction | 4.825 ns | 32 B | 4.641 ns | 32 B | Same allocation; generated was slightly faster in this microbenchmark. | | Service Activator | Execution | 25.48 ns | 256 B | 26.49 ns | 256 B | Same allocation; fluent was slightly faster in this path. | +| Service Layer | Construction | 56.33 ns | 496 B | 41.36 ns | 296 B | Generated reduced construction time and allocation in this microbenchmark. | +| Service Layer | Execution | 151.32 ns | 960 B | 148.10 ns | 872 B | Generated slightly reduced execution time and allocation for the register-customer workflow. | | Specification | Construction | 196.03 ns | 1,704 B | 136.87 ns | 1,008 B | Generated reduced construction time and allocation in this microbenchmark. | | Specification | Execution | 111.25 ns | 344 B | 93.30 ns | 344 B | Same allocation; generated was faster for loan-application evaluation. | | Table Data Gateway | Construction | 9.740 ns | 120 B | 9.698 ns | 120 B | Effectively equivalent for this microbenchmark. | | Table Data Gateway | Execution | 90.51 ns | 600 B | 96.35 ns | 600 B | Same allocation; fluent was slightly faster for the insert-update-query workflow. | +| Transaction Script | Construction | 20.634 ns | 240 B | 5.839 ns | 40 B | Generated materially reduced construction time and allocation in this microbenchmark. | +| Transaction Script | Execution | 184.93 ns | 1,136 B | 98.28 ns | 600 B | Generated reduced execution time and allocation for the submit-order workflow. | | Unit Of Work | Construction | 49.50 ns | 304 B | 46.91 ns | 304 B | Same allocation; generated was slightly faster in this microbenchmark. | | Unit Of Work | Execution | 121.03 ns | 824 B | 96.91 ns | 520 B | Generated reduced execution time and allocation for the checkout commit workflow. | diff --git a/benchmarks/PatternKit.Benchmarks/Application/DomainEventBenchmarks.cs b/benchmarks/PatternKit.Benchmarks/Application/DomainEventBenchmarks.cs new file mode 100644 index 0000000..f1421d5 --- /dev/null +++ b/benchmarks/PatternKit.Benchmarks/Application/DomainEventBenchmarks.cs @@ -0,0 +1,29 @@ +using BenchmarkDotNet.Attributes; +using PatternKit.Application.DomainEvents; +using PatternKit.Examples.DomainEventDemo; + +namespace PatternKit.Benchmarks.Application; + +[BenchmarkCategory("ApplicationArchitecture", "DomainEvent")] +public class DomainEventBenchmarks +{ + [Benchmark(Baseline = true, Description = "Fluent: create domain event dispatcher")] + [BenchmarkCategory("Fluent", "Construction")] + public DomainEventDispatcher Fluent_CreateDispatcher() + => OrderDomainEventPolicies.CreateFluentDispatcher(new OrderEventProjection(), new List()); + + [Benchmark(Description = "Generated: create domain event dispatcher")] + [BenchmarkCategory("Generated", "Construction")] + public IDomainEventDispatcher Generated_CreateDispatcher() + => GeneratedOrderDomainEvents.CreateDispatcher(); + + [Benchmark(Description = "Fluent: dispatch order placed")] + [BenchmarkCategory("Fluent", "Execution")] + public ValueTask Fluent_DispatchOrderPlaced() + => OrderDomainEventDemo.RunFluentAsync(); + + [Benchmark(Description = "Generated: dispatch order placed")] + [BenchmarkCategory("Generated", "Execution")] + public ValueTask Generated_DispatchOrderPlaced() + => OrderDomainEventDemo.RunGeneratedAsync(); +} diff --git a/benchmarks/PatternKit.Benchmarks/Application/ServiceLayerBenchmarks.cs b/benchmarks/PatternKit.Benchmarks/Application/ServiceLayerBenchmarks.cs new file mode 100644 index 0000000..b672b35 --- /dev/null +++ b/benchmarks/PatternKit.Benchmarks/Application/ServiceLayerBenchmarks.cs @@ -0,0 +1,31 @@ +using BenchmarkDotNet.Attributes; +using PatternKit.Application.Repository; +using PatternKit.Application.ServiceLayer; +using PatternKit.Examples.ServiceLayerDemo; + +namespace PatternKit.Benchmarks.Application; + +[BenchmarkCategory("ApplicationArchitecture", "ServiceLayer")] +public class ServiceLayerBenchmarks +{ + [Benchmark(Baseline = true, Description = "Fluent: create service layer operation")] + [BenchmarkCategory("Fluent", "Construction")] + public ServiceLayerOperation Fluent_CreateOperation() + => CustomerServiceLayerPolicies.CreateFluentOperation( + InMemoryRepository.Create(static customer => customer.CustomerId).Build()); + + [Benchmark(Description = "Generated: create service layer operation")] + [BenchmarkCategory("Generated", "Construction")] + public IServiceOperation Generated_CreateOperation() + => GeneratedCustomerServiceLayer.CreateOperation(); + + [Benchmark(Description = "Fluent: register customer")] + [BenchmarkCategory("Fluent", "Execution")] + public ValueTask Fluent_RegisterCustomer() + => CustomerServiceLayerDemo.RunFluentAsync(); + + [Benchmark(Description = "Generated: register customer")] + [BenchmarkCategory("Generated", "Execution")] + public ValueTask Generated_RegisterCustomer() + => CustomerServiceLayerDemo.RunGeneratedAsync(); +} diff --git a/benchmarks/PatternKit.Benchmarks/Application/TransactionScriptBenchmarks.cs b/benchmarks/PatternKit.Benchmarks/Application/TransactionScriptBenchmarks.cs new file mode 100644 index 0000000..6eea4d2 --- /dev/null +++ b/benchmarks/PatternKit.Benchmarks/Application/TransactionScriptBenchmarks.cs @@ -0,0 +1,31 @@ +using BenchmarkDotNet.Attributes; +using PatternKit.Application.Repository; +using PatternKit.Application.TransactionScript; +using PatternKit.Examples.TransactionScriptDemo; + +namespace PatternKit.Benchmarks.Application; + +[BenchmarkCategory("ApplicationArchitecture", "TransactionScript")] +public class TransactionScriptBenchmarks +{ + [Benchmark(Baseline = true, Description = "Fluent: create transaction script")] + [BenchmarkCategory("Fluent", "Construction")] + public TransactionScript Fluent_CreateScript() + => OrderTransactionScriptPolicies.CreateFluentScript( + InMemoryRepository.Create(static order => order.OrderId).Build()); + + [Benchmark(Description = "Generated: create transaction script")] + [BenchmarkCategory("Generated", "Construction")] + public ITransactionScript Generated_CreateScript() + => GeneratedSubmitOrderScript.CreateScript(); + + [Benchmark(Description = "Fluent: submit order")] + [BenchmarkCategory("Fluent", "Execution")] + public ValueTask Fluent_SubmitOrder() + => OrderTransactionScriptDemo.RunFluentAsync(); + + [Benchmark(Description = "Generated: submit order")] + [BenchmarkCategory("Generated", "Execution")] + public ValueTask Generated_SubmitOrder() + => OrderTransactionScriptDemo.RunGeneratedAsync(); +} diff --git a/docs/guides/benchmark-results.md b/docs/guides/benchmark-results.md index f2740b0..952621d 100644 --- a/docs/guides/benchmark-results.md +++ b/docs/guides/benchmark-results.md @@ -17,6 +17,8 @@ The latest measured timings below were captured on Windows 11, Intel Core i9-149 | Cache-Aside | Execution | 216.50 ns | 1,048 B | 208.60 ns | 1,048 B | Same allocation; generated was slightly faster for the miss-then-hit workflow. | | Data Mapper | Construction | 40.56 ns | 288 B | 12.87 ns | 112 B | Generated reduced construction time and allocation in this microbenchmark. | | Data Mapper | Execution | 188.09 ns | 1,104 B | 97.71 ns | 672 B | Generated reduced execution time and allocation for the map-store-load workflow. | +| Domain Event | Construction | 199.5 ns | 1.34 KB | 157.6 ns | 1.04 KB | Generated reduced construction time and allocation in this microbenchmark. | +| Domain Event | Execution | 367.2 ns | 1.77 KB | 346.4 ns | 1.55 KB | Generated reduced execution time and allocation for the order-placed dispatch workflow. | | Leader Election | Construction | 14.28 ns | 104 B | 15.91 ns | 104 B | Same allocation; fluent was slightly faster in this microbenchmark. | | Leader Election | Execution | 43.62 ns | 360 B | 144.37 ns | 312 B | Generated allocated about 13% less memory, while fluent was faster in this path. | | Materialized View | Construction | 140.9 ns | 1.05 KB | 147.4 ns | 1.05 KB | Same allocation; fluent was slightly faster in this microbenchmark. | @@ -35,10 +37,14 @@ The latest measured timings below were captured on Windows 11, Intel Core i9-149 | Scheduler Agent Supervisor | Execution | 177.46 ns | 1,304 B | 180.14 ns | 1,304 B | Effectively equivalent for this scenario. | | Service Activator | Construction | 4.825 ns | 32 B | 4.641 ns | 32 B | Same allocation; generated was slightly faster in this microbenchmark. | | Service Activator | Execution | 25.48 ns | 256 B | 26.49 ns | 256 B | Same allocation; fluent was slightly faster in this path. | +| Service Layer | Construction | 56.33 ns | 496 B | 41.36 ns | 296 B | Generated reduced construction time and allocation in this microbenchmark. | +| Service Layer | Execution | 151.32 ns | 960 B | 148.10 ns | 872 B | Generated slightly reduced execution time and allocation for the register-customer workflow. | | Specification | Construction | 196.03 ns | 1,704 B | 136.87 ns | 1,008 B | Generated reduced construction time and allocation in this microbenchmark. | | Specification | Execution | 111.25 ns | 344 B | 93.30 ns | 344 B | Same allocation; generated was faster for loan-application evaluation. | | Table Data Gateway | Construction | 9.740 ns | 120 B | 9.698 ns | 120 B | Effectively equivalent for this microbenchmark. | | Table Data Gateway | Execution | 90.51 ns | 600 B | 96.35 ns | 600 B | Same allocation; fluent was slightly faster for the insert-update-query workflow. | +| Transaction Script | Construction | 20.634 ns | 240 B | 5.839 ns | 40 B | Generated materially reduced construction time and allocation in this microbenchmark. | +| Transaction Script | Execution | 184.93 ns | 1,136 B | 98.28 ns | 600 B | Generated reduced execution time and allocation for the submit-order workflow. | | Unit Of Work | Construction | 49.50 ns | 304 B | 46.91 ns | 304 B | Same allocation; generated was slightly faster in this microbenchmark. | | Unit Of Work | Execution | 121.03 ns | 824 B | 96.91 ns | 520 B | Generated reduced execution time and allocation for the checkout commit workflow. | diff --git a/docs/guides/benchmarks.md b/docs/guides/benchmarks.md index b6859ce..7a95c90 100644 --- a/docs/guides/benchmarks.md +++ b/docs/guides/benchmarks.md @@ -34,6 +34,8 @@ The following numbers were captured on Windows 11, Intel Core i9-14900K, .NET SD | Cache-Aside | Execution | 216.50 ns | 1,048 B | 208.60 ns | 1,048 B | Same allocation; generated was slightly faster for the miss-then-hit workflow. | | Data Mapper | Construction | 40.56 ns | 288 B | 12.87 ns | 112 B | Generated reduced construction time and allocation in this microbenchmark. | | Data Mapper | Execution | 188.09 ns | 1,104 B | 97.71 ns | 672 B | Generated reduced execution time and allocation for the map-store-load workflow. | +| Domain Event | Construction | 199.5 ns | 1.34 KB | 157.6 ns | 1.04 KB | Generated reduced construction time and allocation in this microbenchmark. | +| Domain Event | Execution | 367.2 ns | 1.77 KB | 346.4 ns | 1.55 KB | Generated reduced execution time and allocation for the order-placed dispatch workflow. | | Leader Election | Construction | 14.28 ns | 104 B | 15.91 ns | 104 B | Same allocation; fluent was slightly faster in this microbenchmark. | | Leader Election | Execution | 43.62 ns | 360 B | 144.37 ns | 312 B | Generated allocated about 13% less memory, while fluent was faster in this path. | | Materialized View | Construction | 140.9 ns | 1.05 KB | 147.4 ns | 1.05 KB | Same allocation; fluent was slightly faster in this microbenchmark. | @@ -52,10 +54,14 @@ The following numbers were captured on Windows 11, Intel Core i9-14900K, .NET SD | Scheduler Agent Supervisor | Execution | 177.46 ns | 1,304 B | 180.14 ns | 1,304 B | Effectively equivalent for this scenario. | | Service Activator | Construction | 4.825 ns | 32 B | 4.641 ns | 32 B | Same allocation; generated was slightly faster in this microbenchmark. | | Service Activator | Execution | 25.48 ns | 256 B | 26.49 ns | 256 B | Same allocation; fluent was slightly faster in this path. | +| Service Layer | Construction | 56.33 ns | 496 B | 41.36 ns | 296 B | Generated reduced construction time and allocation in this microbenchmark. | +| Service Layer | Execution | 151.32 ns | 960 B | 148.10 ns | 872 B | Generated slightly reduced execution time and allocation for the register-customer workflow. | | Specification | Construction | 196.03 ns | 1,704 B | 136.87 ns | 1,008 B | Generated reduced construction time and allocation in this microbenchmark. | | Specification | Execution | 111.25 ns | 344 B | 93.30 ns | 344 B | Same allocation; generated was faster for loan-application evaluation. | | Table Data Gateway | Construction | 9.740 ns | 120 B | 9.698 ns | 120 B | Effectively equivalent for this microbenchmark. | | Table Data Gateway | Execution | 90.51 ns | 600 B | 96.35 ns | 600 B | Same allocation; fluent was slightly faster for the insert-update-query workflow. | +| Transaction Script | Construction | 20.634 ns | 240 B | 5.839 ns | 40 B | Generated materially reduced construction time and allocation in this microbenchmark. | +| Transaction Script | Execution | 184.93 ns | 1,136 B | 98.28 ns | 600 B | Generated reduced execution time and allocation for the submit-order workflow. | | Unit Of Work | Construction | 49.50 ns | 304 B | 46.91 ns | 304 B | Same allocation; generated was slightly faster in this microbenchmark. | | Unit Of Work | Execution | 121.03 ns | 824 B | 96.91 ns | 520 B | Generated reduced execution time and allocation for the checkout commit workflow. |