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

Added AsyncReadWriteLock #1639

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
40 changes: 40 additions & 0 deletions Source/MQTTnet.Benchmarks/AsyncReadWriteLockBenchmark.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Jobs;
using MQTTnet.Internal;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MQTTnet.Benchmarks
{
[SimpleJob(RuntimeMoniker.Net60)]
[SimpleJob(RuntimeMoniker.Net70)]
[MemoryDiagnoser]
public class AsyncReadWriteLockBenchmark : BaseBenchmark
{

[Benchmark]
public async Task Synchronize_100_Read_Tasks()
{
const int tasksCount = 100;
var tasks = new Task[tasksCount];
var asyncReadWriteLock = new AsyncReadWriteLock();

for (var i = 0; i < tasksCount; i++)
{
tasks[i] = Task.Run(async () =>
{
using (await asyncReadWriteLock.EnterReadAsync().ConfigureAwait(false))
{
await Task.Delay(5).ConfigureAwait(false);
}
});
}

await Task.WhenAll(tasks).ConfigureAwait(false);
}

}
}
Loading