Benchmarks

Performance comparisons between MediatorLite and MediatR across four scenarios: simple request dispatch, single pipeline behavior, multiple pipeline behaviors, and notification publishing.

Last updated: 2026-03-29 — automated via CI.

Environment

BenchmarkDotNet v0.15.8, Linux Ubuntu 24.04.4 LTS (Noble Numbat)
AMD EPYC 7763 2.45GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 10.0.201
  [Host]     : .NET 10.0.5 (10.0.5, 10.0.526.15411), X64 RyuJIT x86-64-v3
  Job-YFEFPZ : .NET 10.0.5 (10.0.5, 10.0.526.15411), X64 RyuJIT x86-64-v3

IterationCount=10  WarmupCount=3

Simple Request

Baseline scenario: a single request dispatched to a single handler with no pipeline behaviors.

Method Mean Error StdDev Ratio RatioSD Gen0 Allocated Alloc Ratio
MediatR_SimpleRequest 113.0 ns 1.91 ns 1.26 ns 1.00 0.02 0.0196 328 B 1.00
MediatorLite_SimpleRequest 140.4 ns 1.38 ns 0.91 ns 1.24 0.02 0.0153 256 B 0.78

Single Pipeline Behavior

Request dispatched through one open pipeline behavior (simulating a logging or tracing layer).

Method Mean Error StdDev Ratio Gen0 Allocated Alloc Ratio
MediatR_WithBehavior 205.5 ns 1.90 ns 1.26 ns 1.00 0.0381 640 B 1.00
MediatorLite_WithBehavior 280.3 ns 1.94 ns 1.15 ns 1.36 0.0348 584 B 0.91

Multiple Pipeline Behaviors

Request dispatched through three behaviors (logging, validation, metrics) — a typical production pipeline.

Method Mean Error StdDev Ratio Gen0 Allocated Alloc Ratio
MediatR_WithMultipleBehaviors 349.2 ns 3.36 ns 2.22 ns 1.00 0.0639 1072 B 1.00
MediatorLite_WithMultipleBehaviors 530.9 ns 3.61 ns 2.15 ns 1.52 0.0505 856 B 0.80

Notifications

A notification published to three handlers, comparing MediatR against MediatorLite’s Sequential and Parallel execution strategies.

Method Mean Error StdDev Ratio Gen0 Allocated Alloc Ratio
MediatR_Notification 190.1 ns 2.42 ns 1.60 ns 1.00 0.0367 616 B 1.00
MediatorLite_Sequential_Notification 253.0 ns 2.95 ns 1.76 ns 1.33 0.0134 224 B 0.36
MediatorLite_Parallel_Notification 312.9 ns 0.96 ns 0.63 ns 1.65 0.0176 296 B 0.48

Key Takeaways

MediatorLite consistently allocates less memory across every scenario. The notification sequential mode is especially notable — near-identical latency to MediatR but less than half the allocations. The ValueTask-based pipeline and source-generated dispatch path trade raw per-call speed for a predictable, low-allocation footprint.


Running Benchmarks Locally

cd tests/MediatorLite.Benchmarks
dotnet run --configuration Release -- --filter '*' --exporters json markdown --memory

Results are written to BenchmarkDotNet.Artifacts/results/.

REST API Benchmarks (Production-Like)

The repository also includes a REST API benchmark project at tests/MediatorLite.RestApiBenchmarks. This suite compares MediatorLite and MediatR in end-to-end API scenarios backed by SQLite:

  • In-process transport (TestServer) and real localhost transport (Kestrel)
  • Read-heavy and write-heavy API operations
  • Concurrency scenarios with multiple in-flight requests

Run read/write benchmarks:

dotnet run -c Release --project tests/MediatorLite.RestApiBenchmarks -- --filter '*RestApiReadWriteBenchmarks*'

Run concurrency benchmarks:

dotnet run -c Release --project tests/MediatorLite.RestApiBenchmarks -- --filter '*RestApiConcurrencyBenchmarks*'