-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRequestLoggingMiddlewareBenchmarks.cs
More file actions
61 lines (51 loc) · 1.81 KB
/
Copy pathRequestLoggingMiddlewareBenchmarks.cs
File metadata and controls
61 lines (51 loc) · 1.81 KB
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
using BenchmarkDotNet.Attributes;
using EfMigrationDiff.CLI;
using EfMigrationDiff.Middleware;
using System.Linq;
using System.Threading.Tasks;
namespace EfMigrationDiff.Benchmarks;
[MemoryDiagnoser]
public class RequestLoggingMiddlewareBenchmarks
{
private CommandContext? _context;
private RequestLoggingMiddleware? _middleware;
private RequestLoggingMiddleware? _verboseMiddleware;
[Params(10, 1000)]
public int DataSize;
[GlobalSetup]
public void Setup()
{
var serviceProvider = new DummyServiceProvider();
_context = new CommandContext("test-command", new string[] { "arg1", "arg2" }, serviceProvider);
// Populate DataSize
_context.RawArguments = Enumerable.Range(0, DataSize).Select(i => $"arg{i}").ToArray();
for(int i = 0; i < DataSize; i++)
{
_context.ParsedOptions[$"option{i}"] = $"value{i}";
_context.ParsedArguments.Add($"arg{i}");
}
_middleware = new RequestLoggingMiddleware(new NullLogger(), isVerbose: false);
_verboseMiddleware = new RequestLoggingMiddleware(new NullLogger(), isVerbose: true);
}
[Benchmark]
public async Task<MiddlewareResult> InvokeAsync_NonVerbose()
{
return await _middleware!.InvokeAsync(_context!);
}
[Benchmark]
public async Task<MiddlewareResult> InvokeAsync_Verbose()
{
return await _verboseMiddleware!.InvokeAsync(_context!);
}
}
public class NullLogger : ILogger
{
public void LogInformation(string message) { }
public void LogDebug(string message) { }
public void LogWarning(string message) { }
public void LogError(string message, Exception? exception = null) { }
}
public class DummyServiceProvider : IServiceProvider
{
public object? GetService(System.Type serviceType) => null;
}