-
Notifications
You must be signed in to change notification settings - Fork 21
/
Benchmark.cs
33 lines (25 loc) · 1013 Bytes
/
Benchmark.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
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using LoggingSourceCodeGenerator;
using Microsoft.Extensions.Logging;
BenchmarkRunner.Run<Benchmark>();
[MemoryDiagnoser]
public class Benchmark
{
private readonly UserCreationService _service = new(new NoLogger());
private readonly User _user = new("Steven", "Giesel");
private readonly DateTime _now = DateTime.UtcNow;
[Benchmark]
public void LogCreateUserBad() => _service.LogCreateUserBad(_user, _now);
[Benchmark]
public void LogCreateUserTraditionally() => _service.LogCreateUserTraditionally(_user, _now);
[Benchmark]
public void LogCreateUser() => _service.LogCreateUser(_user, _now);
}
public class NoLogger : ILogger
{
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func<TState, Exception?, string> formatter)
{ }
public bool IsEnabled(LogLevel logLevel) => true;
public IDisposable BeginScope<TState>(TState state) => default;
}