Skip to content

HttpRequestStreamReader overrides for Read Span, ReadAsync Memory, ReadLine and ReadLineAsync #18802

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Apr 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using BenchmarkDotNet.Attributes;

namespace Microsoft.AspNetCore.WebUtilities
{
public class HttpRequestStreamReaderReadLineBenchmark
{
private MemoryStream _stream;

[Params(200, 1000, 1025, 1600)] // Default buffer length is 1024
public int Length { get; set; }

[GlobalSetup]
public void GlobalSetup()
{
var data = new char[Length];

data[Length - 2] = '\r';
data[Length - 1] = '\n';

_stream = new MemoryStream(Encoding.UTF8.GetBytes(data));
}

[Benchmark]
public async Task<string> ReadLineAsync()
{
var reader = CreateReader();
var result = await reader.ReadLineAsync();
Debug.Assert(result.Length == Length - 2);
return result;
}

[Benchmark]
public string ReadLine()
{
var reader = CreateReader();
var result = reader.ReadLine();
Debug.Assert(result.Length == Length - 2);
return result;
}

[Benchmark]
public HttpRequestStreamReader CreateReader()
{
_stream.Seek(0, SeekOrigin.Begin);
return new HttpRequestStreamReader(_stream, Encoding.UTF8);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,13 @@ protected override void Dispose(bool disposing) { }
public override int Peek() { throw null; }
public override int Read() { throw null; }
public override int Read(char[] buffer, int index, int count) { throw null; }
[System.Diagnostics.DebuggerStepThroughAttribute]
public override int Read(System.Span<char> buffer) { throw null; }
public override System.Threading.Tasks.Task<int> ReadAsync(char[] buffer, int index, int count) { throw null; }
[System.Diagnostics.DebuggerStepThroughAttribute]
public override System.Threading.Tasks.ValueTask<int> ReadAsync(System.Memory<char> buffer, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public override string ReadLine() { throw null; }
[System.Diagnostics.DebuggerStepThroughAttribute]
public override System.Threading.Tasks.Task<string> ReadLineAsync() { throw null; }
}
public partial class HttpResponseStreamWriter : System.IO.TextWriter
{
Expand Down
Loading