Skip to content
This repository was archived by the owner on Nov 20, 2018. It is now read-only.

Commit 962ec07

Browse files
authored
Adds PipeWriterAdapter (#1065)
1 parent 49d785c commit 962ec07

File tree

11 files changed

+1266
-2
lines changed

11 files changed

+1266
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,4 @@ project.lock.json
3030
/.vs/
3131
.vscode/
3232
global.json
33+
BenchmarkDotNet.Artifacts/
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System;
5+
using System.IO;
6+
using System.Text;
7+
using System.Threading;
8+
using System.Threading.Tasks;
9+
using BenchmarkDotNet.Attributes;
10+
11+
namespace Microsoft.AspNetCore.Http
12+
{
13+
public class StreamPipeWriterBenchmark
14+
{
15+
private Stream _memoryStream;
16+
private StreamPipeWriter _pipeWriter;
17+
private static byte[] _helloWorldBytes = Encoding.ASCII.GetBytes("Hello World");
18+
private static byte[] _largeWrite = Encoding.ASCII.GetBytes(new string('a', 50000));
19+
20+
[IterationSetup]
21+
public void Setup()
22+
{
23+
_memoryStream = new NoopStream();
24+
_pipeWriter = new StreamPipeWriter(_memoryStream);
25+
}
26+
27+
[Benchmark]
28+
public async Task WriteHelloWorld()
29+
{
30+
await _pipeWriter.WriteAsync(_helloWorldBytes);
31+
}
32+
33+
[Benchmark]
34+
public async Task WriteHelloWorldLargeWrite()
35+
{
36+
await _pipeWriter.WriteAsync(_largeWrite);
37+
}
38+
39+
public class NoopStream : Stream
40+
{
41+
public override bool CanRead => false;
42+
43+
public override bool CanSeek => throw new System.NotImplementedException();
44+
45+
public override bool CanWrite => true;
46+
47+
public override long Length => throw new System.NotImplementedException();
48+
49+
public override long Position { get => throw new System.NotImplementedException(); set => throw new System.NotImplementedException(); }
50+
51+
public override void Flush()
52+
{
53+
}
54+
55+
public override int Read(byte[] buffer, int offset, int count)
56+
{
57+
throw new System.NotImplementedException();
58+
}
59+
60+
public override long Seek(long offset, SeekOrigin origin)
61+
{
62+
throw new System.NotImplementedException();
63+
}
64+
65+
public override void SetLength(long value)
66+
{
67+
}
68+
69+
public override void Write(byte[] buffer, int offset, int count)
70+
{
71+
}
72+
73+
public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
74+
{
75+
return Task.CompletedTask;
76+
}
77+
78+
public override ValueTask WriteAsync(ReadOnlyMemory<byte> buffer, CancellationToken cancellationToken = default(CancellationToken))
79+
{
80+
return default(ValueTask);
81+
}
82+
83+
public override Task FlushAsync(CancellationToken cancellationToken)
84+
{
85+
return Task.CompletedTask;
86+
}
87+
}
88+
}
89+
}

build/dependencies.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
<MoqPackageVersion>4.9.0</MoqPackageVersion>
2525
<NETStandardLibrary20PackageVersion>2.0.3</NETStandardLibrary20PackageVersion>
2626
<SystemBuffersPackageVersion>4.6.0-preview1-26907-04</SystemBuffersPackageVersion>
27+
<SystemIOPipelinesPackageVersion>4.6.0-preview1-26907-04</SystemIOPipelinesPackageVersion>
2728
<SystemTextEncodingsWebPackageVersion>4.6.0-preview1-26907-04</SystemTextEncodingsWebPackageVersion>
2829
<XunitAnalyzersPackageVersion>0.10.0</XunitAnalyzersPackageVersion>
2930
<XunitPackageVersion>2.3.1</XunitPackageVersion>

src/Microsoft.AspNetCore.Http/Microsoft.AspNetCore.Http.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<Description>ASP.NET Core default HTTP feature implementations.</Description>
5-
<TargetFramework>netstandard2.0</TargetFramework>
5+
<TargetFrameworks>netstandard2.0;netcoreapp2.2</TargetFrameworks>
66
<NoWarn>$(NoWarn);CS1591</NoWarn>
77
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
88
<GenerateDocumentationFile>true</GenerateDocumentationFile>
@@ -19,6 +19,7 @@
1919
<PackageReference Include="Microsoft.Extensions.CopyOnWriteDictionary.Sources" PrivateAssets="All" Version="$(MicrosoftExtensionsCopyOnWriteDictionarySourcesPackageVersion)" />
2020
<PackageReference Include="Microsoft.Extensions.ObjectPool" Version="$(MicrosoftExtensionsObjectPoolPackageVersion)" />
2121
<PackageReference Include="Microsoft.Extensions.Options" Version="$(MicrosoftExtensionsOptionsPackageVersion)" />
22+
<PackageReference Include="System.IO.Pipelines" Version="$(SystemIOPipelinesPackageVersion)" />
2223
</ItemGroup>
2324

2425
</Project>

0 commit comments

Comments
 (0)