From edf26be1bffa632ee52ffd5fa36031fe476e49d3 Mon Sep 17 00:00:00 2001 From: Ryan Nowak Date: Wed, 6 Jun 2018 21:46:21 -0700 Subject: [PATCH] move feature around --- .../Matchers/AzureMatcherBenchmark.cs | 7 +++++-- .../Matchers/GithubMatcherBenchmark.cs | 8 ++++++-- .../Matchers/SingleEntryMatcherBenchmark.cs | 14 +++++++++----- .../SmallEntryCountLiteralMatcherBenchark.cs | 14 +++++++++----- 4 files changed, 29 insertions(+), 14 deletions(-) diff --git a/benchmarks/Microsoft.AspNetCore.Routing.Performance/Matchers/AzureMatcherBenchmark.cs b/benchmarks/Microsoft.AspNetCore.Routing.Performance/Matchers/AzureMatcherBenchmark.cs index c1df46a2a5..6d862d4b1e 100644 --- a/benchmarks/Microsoft.AspNetCore.Routing.Performance/Matchers/AzureMatcherBenchmark.cs +++ b/benchmarks/Microsoft.AspNetCore.Routing.Performance/Matchers/AzureMatcherBenchmark.cs @@ -15,6 +15,7 @@ namespace Microsoft.AspNetCore.Routing.Matchers private Matcher _tree; private int[] _samples; + private EndpointFeature _feature; [GlobalSetup] public void Setup() @@ -29,12 +30,14 @@ namespace Microsoft.AspNetCore.Routing.Matchers _route = SetupMatcher(RouteMatcher.CreateBuilder()); _tree = SetupMatcher(TreeRouterMatcher.CreateBuilder()); + + _feature = new EndpointFeature(); } [Benchmark(OperationsPerInvoke = SampleCount)] public async Task LegacyRoute() { - var feature = new EndpointFeature(); + var feature = _feature; for (var i = 0; i < SampleCount; i++) { var sample = _samples[i]; @@ -47,7 +50,7 @@ namespace Microsoft.AspNetCore.Routing.Matchers [Benchmark(OperationsPerInvoke = SampleCount)] public async Task LegacyTreeRouter() { - var feature = new EndpointFeature(); + var feature = _feature; for (var i = 0; i < SampleCount; i++) { var sample = _samples[i]; diff --git a/benchmarks/Microsoft.AspNetCore.Routing.Performance/Matchers/GithubMatcherBenchmark.cs b/benchmarks/Microsoft.AspNetCore.Routing.Performance/Matchers/GithubMatcherBenchmark.cs index 35d8058fdc..3ebc210c8d 100644 --- a/benchmarks/Microsoft.AspNetCore.Routing.Performance/Matchers/GithubMatcherBenchmark.cs +++ b/benchmarks/Microsoft.AspNetCore.Routing.Performance/Matchers/GithubMatcherBenchmark.cs @@ -13,6 +13,8 @@ namespace Microsoft.AspNetCore.Routing.Matchers private Matcher _route; private Matcher _tree; + private EndpointFeature _feature; + [GlobalSetup] public void Setup() { @@ -22,12 +24,14 @@ namespace Microsoft.AspNetCore.Routing.Matchers _route = SetupMatcher(RouteMatcher.CreateBuilder()); _tree = SetupMatcher(TreeRouterMatcher.CreateBuilder()); + + _feature = new EndpointFeature(); } [Benchmark(OperationsPerInvoke = EndpointCount)] public async Task LegacyRoute() { - var feature = new EndpointFeature(); + var feature = _feature; for (var i = 0; i < EndpointCount; i++) { var httpContext = _requests[i]; @@ -39,7 +43,7 @@ namespace Microsoft.AspNetCore.Routing.Matchers [Benchmark(OperationsPerInvoke = EndpointCount)] public async Task LegacyTreeRouter() { - var feature = new EndpointFeature(); + var feature = _feature; for (var i = 0; i < EndpointCount; i++) { var httpContext = _requests[i]; diff --git a/benchmarks/Microsoft.AspNetCore.Routing.Performance/Matchers/SingleEntryMatcherBenchmark.cs b/benchmarks/Microsoft.AspNetCore.Routing.Performance/Matchers/SingleEntryMatcherBenchmark.cs index 9c0b393cd8..f7b93f77c1 100644 --- a/benchmarks/Microsoft.AspNetCore.Routing.Performance/Matchers/SingleEntryMatcherBenchmark.cs +++ b/benchmarks/Microsoft.AspNetCore.Routing.Performance/Matchers/SingleEntryMatcherBenchmark.cs @@ -15,6 +15,8 @@ namespace Microsoft.AspNetCore.Routing.Matchers private Matcher _route; private Matcher _tree; + private EndpointFeature _feature; + [GlobalSetup] public void Setup() { @@ -31,6 +33,8 @@ namespace Microsoft.AspNetCore.Routing.Matchers _instruction = SetupMatcher(InstructionMatcher.CreateBuilder()); _route = SetupMatcher(RouteMatcher.CreateBuilder()); _tree = SetupMatcher(TreeRouterMatcher.CreateBuilder()); + + _feature = new EndpointFeature(); } private Matcher SetupMatcher(MatcherBuilder builder) @@ -42,7 +46,7 @@ namespace Microsoft.AspNetCore.Routing.Matchers [Benchmark(Baseline = true)] public async Task Minimal() { - var feature = new EndpointFeature(); + var feature = _feature; await _minimal.MatchAsync(_requests[0], feature); Validate(_requests[0], _endpoints[0], feature.Endpoint); } @@ -50,7 +54,7 @@ namespace Microsoft.AspNetCore.Routing.Matchers [Benchmark] public async Task Dfa() { - var feature = new EndpointFeature(); + var feature = _feature; await _dfa.MatchAsync(_requests[0], feature); Validate(_requests[0], _endpoints[0], feature.Endpoint); } @@ -58,7 +62,7 @@ namespace Microsoft.AspNetCore.Routing.Matchers [Benchmark] public async Task Instruction() { - var feature = new EndpointFeature(); + var feature = _feature; await _instruction.MatchAsync(_requests[0], feature); Validate(_requests[0], _endpoints[0], feature.Endpoint); } @@ -66,7 +70,7 @@ namespace Microsoft.AspNetCore.Routing.Matchers [Benchmark] public async Task LegacyRoute() { - var feature = new EndpointFeature(); + var feature = _feature; await _route.MatchAsync(_requests[0], feature); Validate(_requests[0], _endpoints[0], feature.Endpoint); } @@ -74,7 +78,7 @@ namespace Microsoft.AspNetCore.Routing.Matchers [Benchmark] public async Task LegacyTreeRouter() { - var feature = new EndpointFeature(); + var feature = _feature; await _tree.MatchAsync(_requests[0], feature); Validate(_requests[0], _endpoints[0], feature.Endpoint); } diff --git a/benchmarks/Microsoft.AspNetCore.Routing.Performance/Matchers/SmallEntryCountLiteralMatcherBenchark.cs b/benchmarks/Microsoft.AspNetCore.Routing.Performance/Matchers/SmallEntryCountLiteralMatcherBenchark.cs index 9e19aafae6..64797f9d0b 100644 --- a/benchmarks/Microsoft.AspNetCore.Routing.Performance/Matchers/SmallEntryCountLiteralMatcherBenchark.cs +++ b/benchmarks/Microsoft.AspNetCore.Routing.Performance/Matchers/SmallEntryCountLiteralMatcherBenchark.cs @@ -15,6 +15,8 @@ namespace Microsoft.AspNetCore.Routing.Matchers private Matcher _route; private Matcher _tree; + private EndpointFeature _feature; + [GlobalSetup] public void Setup() { @@ -31,6 +33,8 @@ namespace Microsoft.AspNetCore.Routing.Matchers _instruction = SetupMatcher(InstructionMatcher.CreateBuilder()); _route = SetupMatcher(RouteMatcher.CreateBuilder()); _tree = SetupMatcher(TreeRouterMatcher.CreateBuilder()); + + _feature = new EndpointFeature(); } // For this case we're specifically targeting the last entry to hit 'worst case' @@ -53,7 +57,7 @@ namespace Microsoft.AspNetCore.Routing.Matchers [Benchmark(Baseline = true)] public async Task Minimal() { - var feature = new EndpointFeature(); + var feature = _feature; await _minimal.MatchAsync(_requests[0], feature); Validate(_requests[0], _endpoints[0], feature.Endpoint); } @@ -61,7 +65,7 @@ namespace Microsoft.AspNetCore.Routing.Matchers [Benchmark] public async Task Dfa() { - var feature = new EndpointFeature(); + var feature = _feature; await _dfa.MatchAsync(_requests[0], feature); Validate(_requests[0], _endpoints[0], feature.Endpoint); } @@ -69,7 +73,7 @@ namespace Microsoft.AspNetCore.Routing.Matchers [Benchmark] public async Task Instruction() { - var feature = new EndpointFeature(); + var feature = _feature; await _instruction.MatchAsync(_requests[0], feature); Validate(_requests[0], _endpoints[0], feature.Endpoint); } @@ -77,7 +81,7 @@ namespace Microsoft.AspNetCore.Routing.Matchers [Benchmark] public async Task LegacyRoute() { - var feature = new EndpointFeature(); + var feature = _feature; await _route.MatchAsync(_requests[0], feature); Validate(_requests[0], _endpoints[0], feature.Endpoint); } @@ -85,7 +89,7 @@ namespace Microsoft.AspNetCore.Routing.Matchers [Benchmark] public async Task LegacyTreeRouter() { - var feature = new EndpointFeature(); + var feature = _feature; await _tree.MatchAsync(_requests[0], feature); Validate(_requests[0], _endpoints[0], feature.Endpoint); }