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
Prev Previous commit
Next Next commit
Devide the #regions into separate C# files
  • Loading branch information
manandre committed Oct 19, 2019
commit 9b9233140d1c615cbabc9ad769ef183d4e0d1a51
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// 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.

namespace System.Threading.Tasks.Dataflow.Tests
{
public class ActionBlockPerfTests : TargetPerfTests<ITargetBlock<int>>
{
public override ITargetBlock<int> CreateBlock() => new ActionBlock<int>(i => { });
}

public class ParallelActionBlockPerfTests : TargetPerfTests<ITargetBlock<int>>
{
public override ITargetBlock<int> CreateBlock() =>
new ActionBlock<int>(
i => { },
new ExecutionDataflowBlockOptions
{
MaxDegreeOfParallelism = Environment.ProcessorCount
}
);
}

public class UnorderedParallelActionBlockPerfTests : TargetPerfTests<ITargetBlock<int>>
{
public override ITargetBlock<int> CreateBlock() =>
new ActionBlock<int>(
i => { },
new ExecutionDataflowBlockOptions
{
MaxDegreeOfParallelism = Environment.ProcessorCount,
EnsureOrdered = false
manandre marked this conversation as resolved.
Show resolved Hide resolved
}
);
}

public class SingleProducerConstrainedActionBlockPerfTests : TargetPerfTests<ITargetBlock<int>>
{
public override ITargetBlock<int> CreateBlock() =>
new ActionBlock<int>(
i => { },
new ExecutionDataflowBlockOptions
{
SingleProducerConstrained = true
}
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// 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.

namespace System.Threading.Tasks.Dataflow.Tests
{
public class BatchBlockPerfTests : PropagatorPerfTests<IPropagatorBlock<int, int[]>, int[]>
{
protected override int ReceiveSize { get; } = 100;
public override IPropagatorBlock<int, int[]> CreateBlock() => new BatchBlock<int>(ReceiveSize);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// 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 System.Collections.Generic;
using BenchmarkDotNet.Attributes;
using MicroBenchmarks;

namespace System.Threading.Tasks.Dataflow.Tests
{
[BenchmarkCategory(Categories.CoreFX)]
public class BatchedJoinBlockPerfTests : SourceBlockPerfTests<BatchedJoinBlock<int, int>, Tuple<IList<int>, IList<int>>>
{
protected override int ReceiveSize { get; } = 100;

public override BatchedJoinBlock<int, int> CreateBlock() => new BatchedJoinBlock<int, int>(ReceiveSize);

[Benchmark(OperationsPerInvoke = 100_000)]
public async Task PostTwiceReceiveOnceParallel()
{
await Task.WhenAll(
Post(block.Target1),
Post(block.Target2),
Receive()
);
}

[Benchmark(OperationsPerInvoke = 100_000)]
public async Task SendAsyncTwiceReceiveAsyncOnceParallel()
{
await Task.WhenAll(
SendAsync(block.Target1),
SendAsync(block.Target2),
ReceiveAsync()
);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// 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;

namespace System.Threading.Tasks.Dataflow.Tests
{
[BenchmarkCategory(Categories.CoreFX)]
public class BroadcastBlockPerfTests : PropagatorPerfTests<IPropagatorBlock<int, int>, int>
{
public override IPropagatorBlock<int, int> CreateBlock() =>
new BroadcastBlock<int>(
i => i,
new ExecutionDataflowBlockOptions
{
MaxDegreeOfParallelism = Environment.ProcessorCount
});
manandre marked this conversation as resolved.
Show resolved Hide resolved

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

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

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 doTask();
block.Complete();
manandre marked this conversation as resolved.
Show resolved Hide resolved

await Task.WhenAll(action1.Completion, action2.Completion);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// 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.

namespace System.Threading.Tasks.Dataflow.Tests
{
public class UnboundedBufferBlockPerfTests : PropagatorPerfTests<IPropagatorBlock<int, int>, int>
{
public override IPropagatorBlock<int, int> CreateBlock() => new BufferBlock<int>();
}

public class BoundedBufferBlockPerfTests : BoundedPropagatorPerfTests<IPropagatorBlock<int, int>, int>
{
public override IPropagatorBlock<int, int> CreateBlock() =>
new BufferBlock<int>(
new DataflowBlockOptions
{
BoundedCapacity = 100
});
}
}
Loading