Skip to content

Commit 604498c

Browse files
committed
Benchmark on transformer count
1 parent b7ad201 commit 604498c

File tree

1 file changed

+7
-16
lines changed

1 file changed

+7
-16
lines changed

src/OpenApi/perf/TransformersBenchmark.cs

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace Microsoft.AspNetCore.OpenApi.Microbenchmarks;
2121
public class TransformersBenchmark : OpenApiDocumentServiceTestBase
2222
{
2323
[Params(10, 100, 1000)]
24-
public int InvocationCount { get; set; }
24+
public int TransformerCount { get; set; }
2525

2626
private readonly IEndpointRouteBuilder _builder = CreateBuilder();
2727
private readonly OpenApiOptions _options = new OpenApiOptions();
@@ -31,7 +31,7 @@ public class TransformersBenchmark : OpenApiDocumentServiceTestBase
3131
public void OperationTransformerAsDelegate_Setup()
3232
{
3333
_builder.MapGet("/", () => { });
34-
for (var i = 0; i <= 1000; i++)
34+
for (var i = 0; i <= TransformerCount; i++)
3535
{
3636
_options.UseOperationTransformer((operation, context, token) =>
3737
{
@@ -46,7 +46,7 @@ public void OperationTransformerAsDelegate_Setup()
4646
public void ActivatedDocumentTransformer_Setup()
4747
{
4848
_builder.MapGet("/", () => { });
49-
for (var i = 0; i <= 1000; i++)
49+
for (var i = 0; i <= TransformerCount; i++)
5050
{
5151
_options.UseTransformer<ActivatedTransformer>();
5252
}
@@ -57,7 +57,7 @@ public void ActivatedDocumentTransformer_Setup()
5757
public void DocumentTransformerAsDelegate_Delegate()
5858
{
5959
_builder.MapGet("/", () => { });
60-
for (var i = 0; i <= 1000; i++)
60+
for (var i = 0; i <= TransformerCount; i++)
6161
{
6262
_options.UseTransformer((document, context, token) =>
6363
{
@@ -71,28 +71,19 @@ public void DocumentTransformerAsDelegate_Delegate()
7171
[Benchmark]
7272
public async Task OperationTransformerAsDelegate()
7373
{
74-
for (var i = 0; i <= InvocationCount; i++)
75-
{
76-
await _documentService.GetOpenApiDocumentAsync();
77-
}
74+
await _documentService.GetOpenApiDocumentAsync();
7875
}
7976

8077
[Benchmark]
8178
public async Task ActivatedDocumentTransformer()
8279
{
83-
for (var i = 0; i <= InvocationCount; i++)
84-
{
85-
await _documentService.GetOpenApiDocumentAsync();
86-
}
80+
await _documentService.GetOpenApiDocumentAsync();
8781
}
8882

8983
[Benchmark]
9084
public async Task DocumentTransformerAsDelegate()
9185
{
92-
for (var i = 0; i <= InvocationCount; i++)
93-
{
94-
await _documentService.GetOpenApiDocumentAsync();
95-
}
86+
await _documentService.GetOpenApiDocumentAsync();
9687
}
9788

9889
private class ActivatedTransformer : IOpenApiDocumentTransformer

0 commit comments

Comments
 (0)