Add DfaMatcherBuilder benchmarks (#777)

This commit is contained in:
James Newton-King 2018-09-06 12:10:20 +12:00 committed by GitHub
parent 35163566a9
commit e5c520b4ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 128 additions and 17 deletions

View File

@ -3,12 +3,11 @@
using System.Threading.Tasks; using System.Threading.Tasks;
using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Attributes;
using Microsoft.AspNetCore.Http.Features;
namespace Microsoft.AspNetCore.Routing.Matching namespace Microsoft.AspNetCore.Routing.Matching
{ {
// Generated from https://github.com/Azure/azure-rest-api-specs // Generated from https://github.com/Azure/azure-rest-api-specs
public partial class MatcherAzureBenchmark : EndpointRoutingBenchmarkBase public class MatcherAzureBenchmark : MatcherAzureBenchmarkBase
{ {
private const int SampleCount = 100; private const int SampleCount = 100;

View File

@ -7,11 +7,11 @@ using Microsoft.AspNetCore.Http;
namespace Microsoft.AspNetCore.Routing.Matching namespace Microsoft.AspNetCore.Routing.Matching
{ {
// This code was generated by the Swaggatherer // This code was generated by the Swaggatherer
public partial class MatcherAzureBenchmark : EndpointRoutingBenchmarkBase public abstract partial class MatcherAzureBenchmarkBase : EndpointRoutingBenchmarkBase
{ {
private const int EndpointCount = 5160; private protected const int EndpointCount = 5160;
private void SetupEndpoints() private protected void SetupEndpoints()
{ {
Endpoints = new RouteEndpoint[5160]; Endpoints = new RouteEndpoint[5160];
Endpoints[0] = CreateEndpoint("/account", "GET"); Endpoints[0] = CreateEndpoint("/account", "GET");
@ -5176,7 +5176,7 @@ namespace Microsoft.AspNetCore.Routing.Matching
Endpoints[5159] = CreateEndpoint("/{tenantID}/groups/{groupObjectId}/$links/members/{memberObjectId}", "DELETE"); Endpoints[5159] = CreateEndpoint("/{tenantID}/groups/{groupObjectId}/$links/members/{memberObjectId}", "DELETE");
} }
private void SetupRequests() private protected void SetupRequests()
{ {
Requests = new HttpContext[5160]; Requests = new HttpContext[5160];
Requests[0] = new DefaultHttpContext(); Requests[0] = new DefaultHttpContext();
@ -25821,7 +25821,7 @@ namespace Microsoft.AspNetCore.Routing.Matching
Requests[5159].Request.Path = "/67fb987d/groups/04d01a8c-6135/$links/members/71b75dbe-0076-"; Requests[5159].Request.Path = "/67fb987d/groups/04d01a8c-6135/$links/members/71b75dbe-0076-";
} }
private Matcher SetupMatcher(MatcherBuilder builder) private protected Matcher SetupMatcher(MatcherBuilder builder)
{ {
builder.AddEndpoint(Endpoints[0]); builder.AddEndpoint(Endpoints[0]);
builder.AddEndpoint(Endpoints[1]); builder.AddEndpoint(Endpoints[1]);

View File

@ -0,0 +1,31 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using BenchmarkDotNet.Attributes;
using Microsoft.Extensions.DependencyInjection;
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 MatcherBuilderAzureBenchmark : MatcherAzureBenchmarkBase
{
private IServiceProvider _services;
[GlobalSetup]
public void Setup()
{
SetupEndpoints();
_services = CreateServices();
}
[Benchmark]
public void Dfa()
{
var builder = _services.GetRequiredService<DfaMatcherBuilder>();
SetupMatcher(builder);
}
}
}

View File

@ -0,0 +1,31 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using BenchmarkDotNet.Attributes;
using Microsoft.Extensions.DependencyInjection;
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 MatcherBuilderGithubBenchmark : MatcherGithubBenchmarkBase
{
private IServiceProvider _services;
[GlobalSetup]
public void Setup()
{
SetupEndpoints();
_services = CreateServices();
}
[Benchmark]
public void Dfa()
{
var builder = _services.GetRequiredService<DfaMatcherBuilder>();
SetupMatcher(builder);
}
}
}

View File

@ -0,0 +1,50 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using BenchmarkDotNet.Attributes;
using Microsoft.Extensions.DependencyInjection;
namespace Microsoft.AspNetCore.Routing.Matching
{
public partial class MatcherBuilderMultipleEntryBenchmark : EndpointRoutingBenchmarkBase
{
private IServiceProvider _services;
[GlobalSetup]
public void Setup()
{
Endpoints = new RouteEndpoint[10];
Endpoints[0] = CreateEndpoint("/product", "GET");
Endpoints[1] = CreateEndpoint("/product/{id}", "GET");
Endpoints[2] = CreateEndpoint("/account", "GET");
Endpoints[3] = CreateEndpoint("/account/{id}");
Endpoints[4] = CreateEndpoint("/account/{id}", "POST");
Endpoints[5] = CreateEndpoint("/account/{id}", "UPDATE");
Endpoints[6] = CreateEndpoint("/v2/account", "GET");
Endpoints[7] = CreateEndpoint("/v2/account/{id}");
Endpoints[8] = CreateEndpoint("/v2/account/{id}", "POST");
Endpoints[9] = CreateEndpoint("/v2/account/{id}", "UPDATE");
_services = CreateServices();
}
private Matcher SetupMatcher(MatcherBuilder builder)
{
for (int i = 0; i < Endpoints.Length; i++)
{
builder.AddEndpoint(Endpoints[i]);
}
return builder.Build();
}
[Benchmark]
public void Dfa()
{
var builder = _services.GetRequiredService<DfaMatcherBuilder>();
SetupMatcher(builder);
}
}
}

View File

@ -9,7 +9,7 @@ namespace Microsoft.AspNetCore.Routing.Matching
{ {
// Generated from https://github.com/APIs-guru/openapi-directory // Generated from https://github.com/APIs-guru/openapi-directory
// Use https://editor2.swagger.io/ to convert from yaml to json- // Use https://editor2.swagger.io/ to convert from yaml to json-
public partial class MatcherGithubBenchmark : EndpointRoutingBenchmarkBase public class MatcherGithubBenchmark : MatcherGithubBenchmarkBase
{ {
private BarebonesMatcher _baseline; private BarebonesMatcher _baseline;
private Matcher _dfa; private Matcher _dfa;

View File

@ -7,11 +7,11 @@ using Microsoft.AspNetCore.Http;
namespace Microsoft.AspNetCore.Routing.Matching namespace Microsoft.AspNetCore.Routing.Matching
{ {
// This code was generated by the Swaggatherer // This code was generated by the Swaggatherer
public partial class MatcherGithubBenchmark : EndpointRoutingBenchmarkBase public partial class MatcherGithubBenchmarkBase : EndpointRoutingBenchmarkBase
{ {
private const int EndpointCount = 243; private protected const int EndpointCount = 243;
private void SetupEndpoints() private protected void SetupEndpoints()
{ {
Endpoints = new RouteEndpoint[243]; Endpoints = new RouteEndpoint[243];
Endpoints[0] = CreateEndpoint("/emojis", "GET"); Endpoints[0] = CreateEndpoint("/emojis", "GET");
@ -259,7 +259,7 @@ namespace Microsoft.AspNetCore.Routing.Matching
Endpoints[242] = CreateEndpoint("/repos/{owner}/{repo}/{archive_format}/{path}", "GET"); Endpoints[242] = CreateEndpoint("/repos/{owner}/{repo}/{archive_format}/{path}", "GET");
} }
private void SetupRequests() private protected void SetupRequests()
{ {
Requests = new HttpContext[243]; Requests = new HttpContext[243];
Requests[0] = new DefaultHttpContext(); Requests[0] = new DefaultHttpContext();
@ -1236,7 +1236,7 @@ namespace Microsoft.AspNetCore.Routing.Matching
Requests[242].Request.Path = "/repos/21a74/f36c8/805b0492-b723-/680ad"; Requests[242].Request.Path = "/repos/21a74/f36c8/805b0492-b723-/680ad";
} }
private Matcher SetupMatcher(MatcherBuilder builder) private protected Matcher SetupMatcher(MatcherBuilder builder)
{ {
builder.AddEndpoint(Endpoints[0]); builder.AddEndpoint(Endpoints[0]);
builder.AddEndpoint(Endpoints[1]); builder.AddEndpoint(Endpoints[1]);

View File

@ -74,21 +74,21 @@ namespace Microsoft.AspNetCore.Routing
// This code was generated by the Swaggatherer // This code was generated by the Swaggatherer
public partial class GeneratedBenchmark : EndpointRoutingBenchmarkBase public partial class GeneratedBenchmark : EndpointRoutingBenchmarkBase
{{ {{
private const int EndpointCount = {3}; private protected const int EndpointCount = {3};
private void SetupEndpoints() private protected void SetupEndpoints()
{{ {{
Endpoints = new RouteEndpoint[{3}]; Endpoints = new RouteEndpoint[{3}];
{0} {0}
}} }}
private void SetupRequests() private protected void SetupRequests()
{{ {{
Requests = new HttpContext[{3}]; Requests = new HttpContext[{3}];
{1} {1}
}} }}
private Matcher SetupMatcher(MatcherBuilder builder) private protected Matcher SetupMatcher(MatcherBuilder builder)
{{ {{
{2} {2}
return builder.Build(); return builder.Build();