Remove old cruft

Our new benchmarks are already much better than this one.
This commit is contained in:
Ryan Nowak 2018-06-05 21:52:27 -07:00
parent 49f839a286
commit 72941a8f35
4 changed files with 21 additions and 129 deletions

View File

@ -18,19 +18,19 @@ namespace Microsoft.AspNetCore.Routing.Matchers
[GlobalSetup] [GlobalSetup]
public void Setup() public void Setup()
{ {
_endpoints = new MatcherEndpoint[1];
_endpoints[0] = CreateEndpoint("/plaintext");
_requests = new HttpContext[1];
_requests[0] = new DefaultHttpContext();
_requests[0].RequestServices = CreateServices();
_requests[0].Request.Path = "/plaintext";
_minimal = SetupMatcher(MinimalMatcher.CreateBuilder()); _minimal = SetupMatcher(MinimalMatcher.CreateBuilder());
_dfa = SetupMatcher(DfaMatcher.CreateBuilder()); _dfa = SetupMatcher(DfaMatcher.CreateBuilder());
_instruction = SetupMatcher(InstructionMatcher.CreateBuilder()); _instruction = SetupMatcher(InstructionMatcher.CreateBuilder());
_route = SetupMatcher(RouteMatcher.CreateBuilder()); _route = SetupMatcher(RouteMatcher.CreateBuilder());
_tree = SetupMatcher(TreeRouterMatcher.CreateBuilder()); _tree = SetupMatcher(TreeRouterMatcher.CreateBuilder());
_endpoints = new MatcherEndpoint[0];
_endpoints[0] = CreateEndpoint("/plaintext");
_requests = new HttpContext[0];
_requests[0] = new DefaultHttpContext();
_requests[0].RequestServices = CreateServices();
_requests[0].Request.Path = "/plaintext";
} }
private Matcher SetupMatcher(MatcherBuilder builder) private Matcher SetupMatcher(MatcherBuilder builder)

View File

@ -18,12 +18,6 @@ namespace Microsoft.AspNetCore.Routing.Matchers
[GlobalSetup] [GlobalSetup]
public void Setup() public void Setup()
{ {
_minimal = SetupMatcher(MinimalMatcher.CreateBuilder());
_dfa = SetupMatcher(DfaMatcher.CreateBuilder());
_instruction = SetupMatcher(InstructionMatcher.CreateBuilder());
_route = SetupMatcher(RouteMatcher.CreateBuilder());
_tree = SetupMatcher(TreeRouterMatcher.CreateBuilder());
_endpoints = new MatcherEndpoint[1]; _endpoints = new MatcherEndpoint[1];
_endpoints[0] = CreateEndpoint("/plaintext"); _endpoints[0] = CreateEndpoint("/plaintext");
@ -31,6 +25,12 @@ namespace Microsoft.AspNetCore.Routing.Matchers
_requests[0] = new DefaultHttpContext(); _requests[0] = new DefaultHttpContext();
_requests[0].RequestServices = CreateServices(); _requests[0].RequestServices = CreateServices();
_requests[0].Request.Path = "/plaintext"; _requests[0].Request.Path = "/plaintext";
_minimal = SetupMatcher(MinimalMatcher.CreateBuilder());
_dfa = SetupMatcher(DfaMatcher.CreateBuilder());
_instruction = SetupMatcher(InstructionMatcher.CreateBuilder());
_route = SetupMatcher(RouteMatcher.CreateBuilder());
_tree = SetupMatcher(TreeRouterMatcher.CreateBuilder());
} }
// For this case we're specifically targeting the last entry to hit 'worst case' // For this case we're specifically targeting the last entry to hit 'worst case'

View File

@ -1,113 +0,0 @@
// 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 System.Linq;
using System.Threading.Tasks;
using BenchmarkDotNet.Attributes;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Routing.Internal;
using Microsoft.AspNetCore.Routing.Template;
using Microsoft.AspNetCore.Routing.Tree;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.ObjectPool;
using Microsoft.Extensions.Options;
namespace Microsoft.AspNetCore.Routing.Performance
{
public class RoutingBenchmark
{
private const int NumberOfRequestTypes = 3;
private const int Iterations = 100;
private readonly IRouter _treeRouter;
private readonly RequestEntry[] _requests;
public RoutingBenchmark()
{
var handler = new RouteHandler((next) => Task.FromResult<object>(null));
var treeBuilder = new TreeRouteBuilder(
NullLoggerFactory.Instance,
new DefaultObjectPool<UriBuildingContext>(new UriBuilderContextPooledObjectPolicy()),
new DefaultInlineConstraintResolver(new OptionsManager<RouteOptions>(new OptionsFactory<RouteOptions>(Enumerable.Empty<IConfigureOptions<RouteOptions>>(), Enumerable.Empty<IPostConfigureOptions<RouteOptions>>()))));
treeBuilder.MapInbound(handler, TemplateParser.Parse("api/Widgets"), "default", 0);
treeBuilder.MapInbound(handler, TemplateParser.Parse("api/Widgets/{id}"), "default", 0);
treeBuilder.MapInbound(handler, TemplateParser.Parse("api/Widgets/search/{term}"), "default", 0);
treeBuilder.MapInbound(handler, TemplateParser.Parse("admin/users/{id}"), "default", 0);
treeBuilder.MapInbound(handler, TemplateParser.Parse("admin/users/{id}/manage"), "default", 0);
_treeRouter = treeBuilder.Build();
_requests = new RequestEntry[NumberOfRequestTypes];
_requests[0].HttpContext = new DefaultHttpContext();
_requests[0].HttpContext.Request.Path = "/api/Widgets/5";
_requests[0].IsMatch = true;
_requests[0].Values = new RouteValueDictionary(new { id = 5 });
_requests[1].HttpContext = new DefaultHttpContext();
_requests[1].HttpContext.Request.Path = "/admin/users/17/mAnage";
_requests[1].IsMatch = true;
_requests[1].Values = new RouteValueDictionary(new { id = 17 });
_requests[2].HttpContext = new DefaultHttpContext();
_requests[2].HttpContext.Request.Path = "/api/Widgets/search/dldldldldld/ddld";
_requests[2].IsMatch = false;
_requests[2].Values = new RouteValueDictionary();
}
[Benchmark(Description = "Attribute Routing", OperationsPerInvoke = Iterations * NumberOfRequestTypes)]
public async Task AttributeRouting()
{
for (var i = 0; i < Iterations; i++)
{
for (var j = 0; j < _requests.Length; j++)
{
var context = new RouteContext(_requests[j].HttpContext);
await _treeRouter.RouteAsync(context);
Verify(context, j);
}
}
}
private void Verify(RouteContext context, int i)
{
if (_requests[i].IsMatch)
{
if (context.Handler == null)
{
throw new InvalidOperationException($"Failed {i}");
}
var values = _requests[i].Values;
if (values.Count != context.RouteData.Values.Count)
{
throw new InvalidOperationException($"Failed {i}");
}
}
else
{
if (context.Handler != null)
{
throw new InvalidOperationException($"Failed {i}");
}
if (context.RouteData.Values.Count != 0)
{
throw new InvalidOperationException($"Failed {i}");
}
}
}
private struct RequestEntry
{
public HttpContext HttpContext;
public bool IsMatch;
public RouteValueDictionary Values;
}
}
}

View File

@ -2,10 +2,15 @@ Compile the solution in Release mode (so binaries are available in release)
To run a specific benchmark add it as parameter. To run a specific benchmark add it as parameter.
``` ```
dotnet run -c Release <benchmark_name> dotnet run -c Release --framework <tfm> <benchmark_name>
```
To run all benchmarks use '*' as the name.
```
dotnet run -c Release --framework <tfm> *
``` ```
If you run without any parameters, you'll be offered the list of all benchmarks and get to choose. If you run without any parameters, you'll be offered the list of all benchmarks and get to choose.
``` ```
dotnet run -c Release dotnet run -c Release --framework <tfm>
``` ```