Welcome to mirror list, hosted at ThFree Co, Russian Federation.

MatcherGithubBenchmark.cs « Matching « Microbenchmarks « perf « Routing « Http « src - github.com/dotnet/aspnetcore.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1afd6ba95e889a902bdd5f60f68cafb8b24aa330 (plain)
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
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Threading.Tasks;
using BenchmarkDotNet.Attributes;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Features;

namespace Microsoft.AspNetCore.Routing.Matching;

// Generated from https://github.com/APIs-guru/openapi-directory
// Use https://editor2.swagger.io/ to convert from yaml to json-
public class MatcherGithubBenchmark : MatcherGithubBenchmarkBase
{
    private BarebonesMatcher _baseline;
    private Matcher _dfa;

    [GlobalSetup]
    public void Setup()
    {
        SetupEndpoints();

        SetupRequests();

        _baseline = (BarebonesMatcher)SetupMatcher(new BarebonesMatcherBuilder());
        _dfa = SetupMatcher(CreateDfaMatcherBuilder());
    }

    [Benchmark(Baseline = true, OperationsPerInvoke = EndpointCount)]
    public async Task Baseline()
    {
        for (var i = 0; i < EndpointCount; i++)
        {
            var httpContext = Requests[i];
            await _baseline.Matchers[i].MatchAsync(httpContext);
            Validate(httpContext, Endpoints[i], httpContext.GetEndpoint());
        }
    }

    [Benchmark(OperationsPerInvoke = EndpointCount)]
    public async Task Dfa()
    {
        for (var i = 0; i < EndpointCount; i++)
        {
            var httpContext = Requests[i];
            await _dfa.MatchAsync(httpContext);
            Validate(httpContext, Endpoints[i], httpContext.GetEndpoint());
        }
    }
}