-
Notifications
You must be signed in to change notification settings - Fork 10.3k
/
Copy pathOpenApiSchemaComparerBenchmark.cs
63 lines (55 loc) · 2.38 KB
/
OpenApiSchemaComparerBenchmark.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
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Globalization;
using BenchmarkDotNet.Attributes;
using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Interfaces;
using Microsoft.OpenApi.Models;
namespace Microsoft.AspNetCore.OpenApi.Microbenchmarks;
public class OpenApiSchemaComparerBenchmark
{
[Params(1, 10, 100)]
public int ElementCount { get; set; }
private OpenApiSchema _schema;
[GlobalSetup]
public void OpenApiSchema_Setup()
{
_schema = new OpenApiSchema
{
AdditionalProperties = GenerateInnerSchema(),
AdditionalPropertiesAllowed = true,
AllOf = Enumerable.Range(0, ElementCount).Select(_ => GenerateInnerSchema()).ToList(),
AnyOf = Enumerable.Range(0, ElementCount).Select(_ => GenerateInnerSchema()).ToList(),
Deprecated = true,
Default = new OpenApiString("default"),
Description = "description",
Discriminator = new OpenApiDiscriminator(),
Example = new OpenApiString("example"),
ExclusiveMaximum = true,
ExclusiveMinimum = true,
Extensions = new Dictionary<string, IOpenApiExtension>
{
["key"] = new OpenApiString("value")
},
ExternalDocs = new OpenApiExternalDocs(),
Enum = Enumerable.Range(0, ElementCount).Select(_ => (IOpenApiAny)new OpenApiString("enum")).ToList(),
OneOf = Enumerable.Range(0, ElementCount).Select(_ => GenerateInnerSchema()).ToList(),
};
static OpenApiSchema GenerateInnerSchema() => new OpenApiSchema
{
Properties = Enumerable.Range(0, 10).ToDictionary(i => i.ToString(CultureInfo.InvariantCulture), _ => new OpenApiSchema()),
Deprecated = true,
Default = new OpenApiString("default"),
Description = "description",
Example = new OpenApiString("example"),
Extensions = new Dictionary<string, IOpenApiExtension>
{
["key"] = new OpenApiString("value")
},
};
}
[Benchmark]
public int OpenApiSchema_GetHashCode() => OpenApiSchemaComparer.Instance.GetHashCode(_schema);
[Benchmark]
public OpenApiSchema OpenApiSchema_Clone() => OpenApiSchemaExtensions.Clone(_schema);
}