@@ -23,7 +23,9 @@ namespace Hexecs.Benchmarks.Collections;
2323[ HideColumns ( "Job" , "Error" , "StdDev" , "Median" , "RatioSD" , "Count" ) ]
2424public class ThreadLocalStackBenchmark
2525{
26- private const int Count = 100_000 ;
26+ [ Params ( 10_000 ) ]
27+ public int Count = 10_000 ;
28+
2729 private const int ThreadCount = 4 ;
2830
2931 private ConcurrentStack < uint > _concurrentStack = null ! ;
@@ -34,10 +36,10 @@ public class ThreadLocalStackBenchmark
3436 [ Benchmark ( Baseline = true ) ]
3537 public int ThreadLocalStack_Parallel ( )
3638 {
39+ var opsPerThread = Count / ThreadCount ;
3740 var result = 0 ;
3841 Parallel . For ( 0 , ThreadCount , _ =>
3942 {
40- const int opsPerThread = Count / ThreadCount ;
4143 for ( var i = 0 ; i < opsPerThread ; i ++ )
4244 {
4345 if ( _threadLocalStack . TryPop ( out var id ) )
@@ -53,10 +55,10 @@ public int ThreadLocalStack_Parallel()
5355 [ Benchmark ]
5456 public int ConcurrentStack_Parallel ( )
5557 {
58+ var opsPerThread = Count / ThreadCount ;
5659 var result = 0 ;
5760 Parallel . For ( 0 , ThreadCount , _ =>
5861 {
59- const int opsPerThread = Count / ThreadCount ;
6062 for ( var i = 0 ; i < opsPerThread ; i ++ )
6163 {
6264 if ( _concurrentStack . TryPop ( out var id ) )
@@ -72,10 +74,10 @@ public int ConcurrentStack_Parallel()
7274 [ Benchmark ]
7375 public int LockedStack_Parallel ( )
7476 {
77+ var opsPerThread = Count / ThreadCount ;
7578 var result = 0 ;
7679 Parallel . For ( 0 , ThreadCount , _ =>
7780 {
78- const int opsPerThread = Count / ThreadCount ;
7981 for ( var i = 0 ; i < opsPerThread ; i ++ )
8082 {
8183 if ( TryPopLocked ( out var id ) )
@@ -103,7 +105,7 @@ public void Setup()
103105 _threadLocalStack . Push ( i ) ;
104106 }
105107 }
106-
108+
107109 [ GlobalCleanup ]
108110 public void Cleanup ( )
109111 {
0 commit comments