-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
149 additions
and
1 deletion.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
src/AsyncKeyLock.Benchmarks/AsyncKeyLock.Benchmarks.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<OutputType>Exe</OutputType> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="AsyncKeyedLock" Version="6.1.1" /> | ||
<PackageReference Include="BenchmarkDotNet" Version="0.13.4" /> | ||
<PackageReference Include="NeoSmart.AsyncLock" Version="3.2.1" /> | ||
<PackageReference Include="Nito.AsyncEx" Version="5.1.2" /> | ||
<PackageReference Include="SixLabors.ImageSharp.Web" Version="2.0.2" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\AsyncKeyLock\AsyncKeyLock.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
using BenchmarkDotNet.Attributes; | ||
using BenchmarkDotNet.Jobs; | ||
|
||
namespace AsyncKeyLock.Benchmarks; | ||
|
||
[MemoryDiagnoser] | ||
public class BenchmarkSimpleKeyLock | ||
{ | ||
[GlobalSetup] | ||
public void GlobalSetup() | ||
{ | ||
_AsyncKeyLock = new AsyncLock<string>(); | ||
_AsyncKeyedLock = new AsyncKeyedLock.AsyncKeyedLocker<string>(); | ||
_ImageSharpWebLock = new SixLabors.ImageSharp.Web.Synchronization.AsyncKeyLock<string>(); | ||
} | ||
|
||
private AsyncLock<string> _AsyncKeyLock; | ||
private AsyncKeyedLock.AsyncKeyedLocker<string> _AsyncKeyedLock; | ||
private SixLabors.ImageSharp.Web.Synchronization.AsyncKeyLock<string> _ImageSharpWebLock; | ||
|
||
[Params(1_00, 1_000, 10_000)] | ||
public int NumberOfLocks; | ||
|
||
[Benchmark(Baseline = true)] | ||
public async Task AsyncKeyLock() | ||
{ | ||
for (int i = 0; i < NumberOfLocks; i++) | ||
{ | ||
using (await _AsyncKeyLock.WriterLockAsync(string.Empty)) | ||
{ | ||
|
||
} | ||
} | ||
} | ||
|
||
[Benchmark] | ||
public async Task AsyncKeyedLock() | ||
{ | ||
for (int i = 0; i < NumberOfLocks; i++) | ||
{ | ||
using (await _AsyncKeyedLock.LockAsync(string.Empty)) | ||
{ | ||
|
||
} | ||
} | ||
} | ||
|
||
[Benchmark] | ||
public async Task ImageSharpWeb() | ||
{ | ||
for (int i = 0; i < NumberOfLocks; i++) | ||
{ | ||
using (await _ImageSharpWebLock.LockAsync(string.Empty)) | ||
{ | ||
|
||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using BenchmarkDotNet.Attributes; | ||
|
||
namespace AsyncKeyLock.Benchmarks; | ||
|
||
[MemoryDiagnoser] | ||
public class BenchmarkSimpleWriterLock | ||
{ | ||
[GlobalSetup] | ||
public void GlobalSetup() | ||
{ | ||
_AsyncKeyLock = new AsyncLock(); | ||
_NeoSmartLock = new NeoSmart.AsyncLock.AsyncLock(); | ||
_NitoLock = new Nito.AsyncEx.AsyncLock(); | ||
} | ||
|
||
private AsyncLock _AsyncKeyLock; | ||
private NeoSmart.AsyncLock.AsyncLock _NeoSmartLock; | ||
private Nito.AsyncEx.AsyncLock _NitoLock; | ||
|
||
[Params(1_00, 1_000, 10_000)] | ||
public int NumberOfLocks; | ||
|
||
[Benchmark(Baseline = true)] | ||
public async Task AsyncKeyLock() | ||
{ | ||
for (int i = 0; i < NumberOfLocks; i++) | ||
{ | ||
using (await _AsyncKeyLock.WriterLockAsync()) | ||
{ | ||
|
||
} | ||
} | ||
} | ||
|
||
[Benchmark] | ||
public async Task NeoSmart() | ||
{ | ||
for (int i = 0; i < NumberOfLocks; i++) | ||
{ | ||
using (await _NeoSmartLock.LockAsync()) | ||
{ | ||
|
||
} | ||
} | ||
} | ||
|
||
[Benchmark] | ||
public async Task Nito() | ||
{ | ||
for (int i = 0; i < NumberOfLocks; i++) | ||
{ | ||
using (await _NitoLock.LockAsync()) | ||
{ | ||
|
||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
using AsyncKeyLock.Benchmarks; | ||
using BenchmarkDotNet.Running; | ||
|
||
BenchmarkRunner.Run<BenchmarkSimpleKeyLock>(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters