-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSingleMessageHandlerBenchmarks.cs
74 lines (56 loc) · 2.2 KB
/
SingleMessageHandlerBenchmarks.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using BenchmarkDotNet.Attributes;
using CQRSlite.Commands;
using CQRSlite.Routing;
using MediatR;
using Xer.Delegator.Registrations;
namespace Xer.Delegator.Benchmarks
{
[MemoryDiagnoser]
public class SingleMessageHandlerBenchmarks
{
#region Declarations
private IMessageDelegator _delegator;
private IMediator _mediator;
private ICommandSender _commandSender;
#endregion Declarations
#region Setup
[GlobalSetup]
public void Setup()
{
// Delegator.
var reg = new SingleMessageHandlerRegistration();
reg.Register<TestMessage>(handleMessage);
_delegator = new MessageDelegator(reg.BuildMessageHandlerResolver());
// Mediatr.
var requestHandler = new TestMediatrRequestHandler();
_mediator = new Mediator((t) => requestHandler, (t) => Enumerable.Empty<object>());
// CQRSLite.
Router router = new Router();
router.RegisterHandler<TestCqrsliteCommand>(handleCqrsliteCommand);
_commandSender = router;
}
#endregion Setup
#region Benchmarks
[Benchmark]
public Task BenchmarkDelegator() => _delegator.SendAsync(new TestMessage());
[Benchmark]
public Task BenchmarkCqrsLite() => _commandSender.Send(new TestCqrsliteCommand());
[Benchmark]
public Task BenchmarkMediatr() => _mediator.Send(new TestMediatrRequest());
#endregion Benchmarks
private Task handleMessage(TestMessage message, CancellationToken ct) => Task.CompletedTask;
private Task handleCqrsliteCommand(TestCqrsliteCommand message, CancellationToken ct) => Task.CompletedTask;
class TestCqrsliteCommand : ICommand
{
public int ExpectedVersion { get; }
}
class TestMediatrRequest : IRequest { }
class TestMediatrRequestHandler : IRequestHandler<TestMediatrRequest>
{
public Task Handle(TestMediatrRequest message, CancellationToken cancellationToken) => Task.CompletedTask;
}
}
}