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
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
Prev Previous commit
Next Next commit
Add BroadcastBlock Dataflow perf tests
  • Loading branch information
manandre committed Oct 17, 2019
commit d1a51805061c993cc35f8c6b7dc505951feaa956
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,63 @@ public override IPropagatorBlock<int, int> CreateBlock()
}
}

public class TransformManyBlockPerfTests : DefaultPropagatorPerfTests
{
public override IPropagatorBlock<int, int> CreateBlock() =>
new TransformManyBlock<int, int>(
i => new int[] { i },
new ExecutionDataflowBlockOptions
{
MaxDegreeOfParallelism = Environment.ProcessorCount
});
}

[BenchmarkCategory(Categories.CoreFX)]
public class BroadcastBlockPerfTests : DefaultPropagatorPerfTests
{
public override IPropagatorBlock<int, int> CreateBlock() =>
new BroadcastBlock<int>(
i => i,
new ExecutionDataflowBlockOptions
{
MaxDegreeOfParallelism = Environment.ProcessorCount
});

[Benchmark(OperationsPerInvoke = 100_000)]
public async Task PostMultiReceiveParallel()
{
var action1 = new ActionBlock<int>(i => { });
var action2 = new ActionBlock<int>(i => { });
block.LinkTo(action1, new DataflowLinkOptions { PropagateCompletion = true });
block.LinkTo(action2, new DataflowLinkOptions { PropagateCompletion = true });

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

await Task.WhenAll(action1.Completion, action2.Completion);
}

[Benchmark(OperationsPerInvoke = 100_000)]
public async Task SendMultiReceiveAsyncParallel()
{
var action1 = new ActionBlock<int>(i => { });
var action2 = new ActionBlock<int>(i => { });
block.LinkTo(action1, new DataflowLinkOptions { PropagateCompletion = true });
block.LinkTo(action2, new DataflowLinkOptions { PropagateCompletion = true });

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

await Task.WhenAll(action1.Completion, action2.Completion);
}
}

[BenchmarkCategory(Categories.CoreFX)]
public abstract class PerfTests<T> where T : IDataflowBlock
{
Expand Down