|
8 | 8 | using KeyedSemaphores;
|
9 | 9 | using ListShuffle;
|
10 | 10 | using NeoSmart.Synchronization;
|
| 11 | +using Stl.Locking; |
11 | 12 |
|
12 | 13 | namespace AsyncKeyedLockBenchmarks
|
13 | 14 | {
|
@@ -574,6 +575,46 @@ public async Task DaoIndividualLock()
|
574 | 575 | await RunTests(DaoIndividualLockTasks).ConfigureAwait(false);
|
575 | 576 | #pragma warning restore CS8604 // Possible null reference argument.
|
576 | 577 | }
|
577 |
| - #endregion SimpleHelpers.NamedLock |
| 578 | + #endregion Dao.IndividualLock |
| 579 | + |
| 580 | + #region Stl.Fusion.AsyncLockSet |
| 581 | + public AsyncLockSet<string> AsyncLockSetLocks { get; set; } |
| 582 | + public ParallelQuery<Task>? AsyncLockSetTasks { get; set; } |
| 583 | + |
| 584 | + [IterationSetup(Target = nameof(StlFusionAsyncLockSet))] |
| 585 | + public void SetupAsyncLockSet() |
| 586 | + { |
| 587 | + if (NumberOfLocks != Contention) |
| 588 | + { |
| 589 | + AsyncLockSetLocks = new AsyncLockSet<string>(LockReentryMode.Unchecked, Environment.ProcessorCount, NumberOfLocks); |
| 590 | + AsyncLockSetTasks = ShuffledIntegers |
| 591 | + .Select(async i => |
| 592 | + { |
| 593 | + var key = (i % NumberOfLocks).ToString(); |
| 594 | + |
| 595 | + using (var myLock = await AsyncLockSetLocks.Lock(key).ConfigureAwait(false)) |
| 596 | + { |
| 597 | + Operation(); |
| 598 | + } |
| 599 | + |
| 600 | + await Task.Yield(); |
| 601 | + }).AsParallel(); |
| 602 | + } |
| 603 | + } |
| 604 | + |
| 605 | + [IterationCleanup(Target = nameof(StlFusionAsyncLockSet))] |
| 606 | + public void CleanupAsyncLockSet() |
| 607 | + { |
| 608 | + AsyncLockSetTasks = null; |
| 609 | + } |
| 610 | + |
| 611 | + [Benchmark(Description = "Stl.Fusion.AsyncLockSet")] |
| 612 | + public async Task StlFusionAsyncLockSet() |
| 613 | + { |
| 614 | +#pragma warning disable CS8604 // Possible null reference argument. |
| 615 | + await RunTests(AsyncLockSetTasks).ConfigureAwait(false); |
| 616 | +#pragma warning restore CS8604 // Possible null reference argument. |
| 617 | + } |
| 618 | + #endregion Stl.Fusion.AsyncLockSet |
578 | 619 | }
|
579 | 620 | }
|
0 commit comments