Skip to content
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
Expand Up @@ -4,7 +4,7 @@

namespace System.IO.Pipes.Tests
{
public class Perf_AnonymousPipeStream_ServerIn_ClientOut : Perf_PipeTest
public class Perf_AnonymousPipeStream : Perf_PipeTest
{
protected override ServerClientPair CreateServerClientPair()
{
Expand All @@ -14,15 +14,4 @@ protected override ServerClientPair CreateServerClientPair()
return ret;
}
}

public class Perf_AnonymousPipeStream_ServerOut_ClientIn : Perf_PipeTest
{
protected override ServerClientPair CreateServerClientPair()
{
ServerClientPair ret = new ServerClientPair();
ret.writeablePipe = new AnonymousPipeServerStream(PipeDirection.Out);
ret.readablePipe = new AnonymousPipeClientStream(PipeDirection.In, ((AnonymousPipeServerStream)ret.writeablePipe).ClientSafePipeHandle);
return ret;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,56 +2,22 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using BenchmarkDotNet.Attributes;
using System.Threading.Tasks;

namespace System.IO.Pipes.Tests
{
public class Perf_NamedPipeStream_ServerOut_ClientIn : Perf_PipeTest
public class Perf_NamedPipeStream : Perf_PipeTest
{
protected override ServerClientPair CreateServerClientPair()
{
ServerClientPair ret = new ServerClientPair();
string pipeName = GetUniquePipeName();
var writeablePipe = new NamedPipeServerStream(pipeName, PipeDirection.Out, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous);
var readablePipe = new NamedPipeClientStream(".", pipeName, PipeDirection.In, PipeOptions.Asynchronous);
[Params(PipeOptions.None, PipeOptions.Asynchronous)]
public PipeOptions Options { get; set; }

Task clientConnect = readablePipe.ConnectAsync();
writeablePipe.WaitForConnection();
clientConnect.Wait();

ret.readablePipe = readablePipe;
ret.writeablePipe = writeablePipe;
return ret;
}
}

public class Perf_NamedPipeStream_ServerIn_ClientOut : Perf_PipeTest
{
protected override ServerClientPair CreateServerClientPair()
{
ServerClientPair ret = new ServerClientPair();
string pipeName = GetUniquePipeName();
var readablePipe = new NamedPipeServerStream(pipeName, PipeDirection.In, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous);
var writeablePipe = new NamedPipeClientStream(".", pipeName, PipeDirection.Out, PipeOptions.Asynchronous);

Task clientConnect = writeablePipe.ConnectAsync();
readablePipe.WaitForConnection();
clientConnect.Wait();

ret.readablePipe = readablePipe;
ret.writeablePipe = writeablePipe;
return ret;
}
}

public class Perf_NamedPipeStream_ServerInOut_ClientInOut : Perf_PipeTest
{
protected override ServerClientPair CreateServerClientPair()
{
ServerClientPair ret = new ServerClientPair();
string pipeName = GetUniquePipeName();
var readablePipe = new NamedPipeServerStream(pipeName, PipeDirection.InOut, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous);
var writeablePipe = new NamedPipeClientStream(".", pipeName, PipeDirection.InOut, PipeOptions.Asynchronous);
var readablePipe = new NamedPipeServerStream(pipeName, PipeDirection.InOut, 1, PipeTransmissionMode.Byte, Options);
var writeablePipe = new NamedPipeClientStream(".", pipeName, PipeDirection.InOut, Options);

Task clientConnect = writeablePipe.ConnectAsync();
readablePipe.WaitForConnection();
Expand Down
55 changes: 49 additions & 6 deletions src/benchmarks/micro/libraries/System.IO.Pipes/Perf.PipeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ namespace System.IO.Pipes.Tests
[BenchmarkCategory(Categories.Libraries, Categories.NoWASM)]
public abstract class Perf_PipeTest : PipeTestBase
{
private const int Iterations = 1000;

[Params(1000000)]
public int size;

Expand All @@ -32,15 +34,56 @@ public void Setup()
[GlobalCleanup]
public void Cleanup() => _serverClientPair.Dispose();

[Benchmark]
[Benchmark(OperationsPerInvoke = Iterations)]
public async Task ReadWrite()
{
Task write = Task.Run(() => _serverClientPair.writeablePipe.Write(_sent, 0, _sent.Length));
int totalReadLength = 0;
while (totalReadLength < _sent.Length)
Task write = Task.Run(delegate
{
for (int i = 0; i < Iterations; i++)
{
_serverClientPair.writeablePipe.Write(_sent, 0, _sent.Length);
}
});

for (int i = 0; i < Iterations; i++)
{
int totalReadLength = 0;
while (totalReadLength < _sent.Length)
{
totalReadLength += _serverClientPair.readablePipe.Read(_received, totalReadLength, size - totalReadLength);
}
}

await write;
}

[Benchmark(OperationsPerInvoke = Iterations)]
public async Task ReadWriteAsync()
{
Task write = Task.Run(async delegate
{
for (int i = 0; i < Iterations; i++)
{
#if !NETFRAMEWORK
await _serverClientPair.writeablePipe.WriteAsync(_sent);
#else
await _serverClientPair.writeablePipe.WriteAsync(_sent, 0, _sent.Length);
#endif
}
});

for (int i = 0; i < Iterations; i++)
{
int readLength = _serverClientPair.readablePipe.Read(_received, totalReadLength, size - totalReadLength);
totalReadLength += readLength;
int totalReadLength = 0;
while (totalReadLength < _sent.Length)
{
totalReadLength += await
#if !NETFRAMEWORK
_serverClientPair.readablePipe.ReadAsync(_received.AsMemory(totalReadLength));
#else
_serverClientPair.readablePipe.ReadAsync(_received, totalReadLength, size - totalReadLength);
#endif
}
}

await write;
Expand Down