Skip to content
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

Create benchmarks for System.Threading.Tasks.Dataflow #951

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Create BufferBlock Dataflow perf tests
  • Loading branch information
manandre committed Oct 16, 2019
commit aaca2504f178d9dd1adb5ee84ded8f49042582f5
1 change: 1 addition & 0 deletions src/benchmarks/micro/MicroBenchmarks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<PackageReference Include="System.Runtime.Serialization.Json" Version="4.3.0" />
<PackageReference Include="System.Security.Cryptography.Primitives" Version="4.3.0" />
<PackageReference Include="System.Threading.Channels" Version="4.5.0" />
<PackageReference Include="System.Threading.Tasks.Dataflow" Version="4.10.0" />
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.2" />
<PackageReference Include="System.Xml.XmlSerializer" Version="4.3.0" />
<PackageReference Include="Utf8Json" Version="1.3.7" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
// Licensed to the .NET Foundation under one or more agreements.
// 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 MicroBenchmarks;

//#pragma warning disable CS1998 // async methods without awaits

namespace System.Threading.Tasks.Dataflow.Tests
{
[BenchmarkCategory(Categories.CoreFX)]
public class Perf_Dataflow
{
[Benchmark]
public async Task BufferBlock_Completion()
{
var block = new BufferBlock<int>();
block.Complete();
await block.Completion;
manandre marked this conversation as resolved.
Show resolved Hide resolved
}

[Benchmark(OperationsPerInvoke = 100_000)]
public void BufferBlock_Post()
{
var block = new BufferBlock<int>();
for (int i = 0; i < 100_000; i++)
{
block.Post(i);
}
}

[Benchmark(OperationsPerInvoke = 100_000)]
public async Task BufferBlock_SendAsync()
{
var block = new BufferBlock<int>();
for (int i = 0; i < 100_000; i++)
{
await block.SendAsync(i);
}
}

[Benchmark(OperationsPerInvoke = 100_000)]
public void BufferBlock_PostReceiveSequential()
{
var block = new BufferBlock<int>();
for (int i = 0; i < 100_000; i++)
{
block.Post(i);
}

for (int i = 0; i < 100_000; i++)
{
block.Receive();
}
}

[Benchmark(OperationsPerInvoke = 100_000)]
public async Task BufferBlock_SendReceiveAsyncSequential()
{
var block = new BufferBlock<int>();
for (int i = 0; i < 100_000; i++)
{
await block.SendAsync(i);
}

for (int i = 0; i < 100_000; i++)
{
await block.ReceiveAsync();
}
}

[Benchmark(OperationsPerInvoke = 100_000)]
public async Task BufferBlock_PostReceiveParallel()
{
var block = new BufferBlock<int>();
await Task.WhenAll(Post(), Receive());

Task Post() => Task.Run(()=>
{
for (int i = 0; i < 100_000; i++)
{
block.Post(i);
}
});

Task Receive() => Task.Run(()=>
{
for (int i = 0; i < 100_000; i++)
{
block.Receive();
}
});
}

[Benchmark(OperationsPerInvoke = 100_000)]
public async Task BufferBlock_SendReceiveAsyncParallel()
{
var block = new BufferBlock<int>();
await Task.WhenAll(SendAsync(), ReceiveAsync());

async Task SendAsync()
{
for (int i = 0; i < 100_000; i++)
{
await block.SendAsync(i);
}
}

async Task ReceiveAsync()
{
for (int i = 0; i < 100_000; i++)
{
await block.ReceiveAsync();
}
}
}
}
}