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
Fix BroadcastBlock benchmark hang up
Refactoring is not always your friend...
  • Loading branch information
manandre committed Oct 18, 2019
commit a12eb1707f0ee1baa8ff698516cda4f00b863960
Original file line number Diff line number Diff line change
Expand Up @@ -163,20 +163,20 @@ public override IPropagatorBlock<int, int> CreateBlock() =>
});

[Benchmark(OperationsPerInvoke = 100_000)]
public Task PostMultiReceiveParallel() => MultiParallel(Post());
public Task PostMultiReceiveParallel() => MultiParallel(() => Post());

[Benchmark(OperationsPerInvoke = 100_000)]
public Task SendMultiReceiveAsyncParallel() => MultiParallel(SendAsync());
public Task SendMultiReceiveAsyncParallel() => MultiParallel(() => SendAsync());

private async Task MultiParallel(Task task)
private async Task MultiParallel(Func<Task> doTask)
{
var options = new DataflowLinkOptions { PropagateCompletion = true };
var action1 = new ActionBlock<int>(i => { });
var action2 = new ActionBlock<int>(i => { });
block.LinkTo(action1, options);
block.LinkTo(action2, options);

await task;
await doTask();
block.Complete();

await Task.WhenAll(action1.Completion, action2.Completion);
Expand Down Expand Up @@ -271,11 +271,11 @@ public async Task Completion()
await block.Completion;
manandre marked this conversation as resolved.
Show resolved Hide resolved
}

protected static Task Post(ITargetBlock<int> target) => Task.Run(() =>
protected static Task Post(ITargetBlock<int> target, bool retry = false) => Task.Run(() =>
{
for (int i = 0; i < 100_000; i++)
{
while (!target.Post(i)) ;
while (!target.Post(i) && retry) ;
}
});

Expand Down Expand Up @@ -371,7 +371,7 @@ public abstract class BoundedPropagatorPerfTests<T, U> : PerfTests<T> where T :
[Benchmark(OperationsPerInvoke = 100_000)]
public async Task PostReceiveParallel()
{
await Task.WhenAll(Post(block), Receive(block));
await Task.WhenAll(Post(block, retry: true), Receive(block));
}

[Benchmark(OperationsPerInvoke = 100_000)]
Expand Down