This repository has been archived by the owner on Nov 27, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
182 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ packages/ | |
artifacts/ | ||
PublishProfiles/ | ||
.vs/ | ||
.vscode/ | ||
.build/ | ||
.testPublish/ | ||
bower_components/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp2.2</TargetFramework> | ||
<TargetFramework Condition="'$(BenchmarksTargetFramework)' != ''">$(BenchmarksTargetFramework)</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<!-- These references are used when running locally --> | ||
<ItemGroup Condition="'$(BenchmarksTargetFramework)' == ''"> | ||
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.Routing\Microsoft.AspNetCore.Routing.csproj" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="$(MicrosoftAspNetCoreServerKestrelPackageVersion)" /> | ||
</ItemGroup> | ||
|
||
<!-- These references are used when running on the Benchmarks Server --> | ||
<ItemGroup Condition="'$(BenchmarksTargetFramework)' != ''"> | ||
<PackageReference Include="Microsoft.AspNetCore.App" Version="$(MicrosoftAspNetCoreAppPackageVersion)" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// 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 Microsoft.AspNetCore.Hosting; | ||
using Microsoft.Extensions.Configuration; | ||
|
||
namespace Benchmarks | ||
{ | ||
public class Program | ||
{ | ||
public static void Main(string[] args) | ||
{ | ||
GetWebHostBuilder(args).Build().Run(); | ||
} | ||
|
||
public static IWebHostBuilder GetWebHostBuilder(string[] args) | ||
{ | ||
var config = new ConfigurationBuilder() | ||
.Build(); | ||
|
||
// Consoler logger has a major impact on perf results, so do not use | ||
// default builder. | ||
|
||
return new WebHostBuilder() | ||
.UseConfiguration(config) | ||
.UseKestrel() | ||
.UseStartup<Startup>(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// 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 Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Routing; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using System.Text; | ||
|
||
namespace Benchmarks | ||
{ | ||
public class Startup | ||
{ | ||
private static readonly byte[] _helloWorldPayload = Encoding.UTF8.GetBytes("Hello, World!"); | ||
|
||
public void ConfigureServices(IServiceCollection services) | ||
{ | ||
services.AddRouting(); | ||
} | ||
|
||
public void Configure(IApplicationBuilder app) | ||
{ | ||
app.UseRouter(routes => | ||
{ | ||
routes.MapRoute("/plaintext", (httpContext) => | ||
{ | ||
var response = httpContext.Response; | ||
var payloadLength = _helloWorldPayload.Length; | ||
response.StatusCode = 200; | ||
response.ContentType = "text/plain"; | ||
response.ContentLength = payloadLength; | ||
return response.Body.WriteAsync(_helloWorldPayload, 0, payloadLength); | ||
}); | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"Default": { | ||
"Client": "Wrk", | ||
"PresetHeaders": "Plaintext", | ||
"ClientProperties": { | ||
"ScriptName": "pipeline", | ||
"PipelineDepth": 16 | ||
}, | ||
"Source": { | ||
"Repository": "https://github.com/aspnet/routing.git", | ||
"BranchOrCommit": "dev", | ||
"Project": "benchmarkapps/Benchmarks/Benchmarks.csproj" | ||
}, | ||
"Port": 8080 | ||
}, | ||
"Plaintext": { | ||
"Path": "/plaintext" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
test/Microsoft.AspNetCore.Routing.FunctionalTests/BenchmarksTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// 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. | ||
|
||
#if NETCOREAPP2_2 | ||
using System; | ||
using System.Net; | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.TestHost; | ||
using Xunit; | ||
|
||
namespace Microsoft.AspNetCore.Routing.FunctionalTests | ||
{ | ||
public class BenchmarksTest : IDisposable | ||
{ | ||
private readonly HttpClient _client; | ||
private readonly TestServer _testServer; | ||
|
||
public BenchmarksTest() | ||
{ | ||
var webHostBuilder = Benchmarks.Program.GetWebHostBuilder(args: null); | ||
_testServer = new TestServer(webHostBuilder); | ||
_client = _testServer.CreateClient(); | ||
_client.BaseAddress = new Uri("http://localhost"); | ||
} | ||
|
||
[Fact] | ||
public async Task RouteHandlerWritesResponse() | ||
{ | ||
// Arrange | ||
var expectedContentType = "text/plain"; | ||
var expectedContent = "Hello, World!"; | ||
|
||
// Act | ||
var response = await _client.GetAsync("/plaintext"); | ||
|
||
// Assert | ||
Assert.Equal(HttpStatusCode.OK, response.StatusCode); | ||
Assert.NotNull(response.Content); | ||
Assert.NotNull(response.Content.Headers.ContentType); | ||
Assert.Equal(expectedContentType, response.Content.Headers.ContentType.MediaType); | ||
var actualContent = await response.Content.ReadAsStringAsync(); | ||
Assert.Equal(expectedContent, actualContent); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
_testServer.Dispose(); | ||
_client.Dispose(); | ||
} | ||
} | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters