Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit b01e361

Browse files
kouvelstephentoub
authored andcommitted
Increase iteration counts in threading perf tests (#28712)
Relevant to https://github.com/dotnet/coreclr/issues/17345
1 parent 6ae0da1 commit b01e361

File tree

6 files changed

+36
-25
lines changed

6 files changed

+36
-25
lines changed

src/System.Threading/tests/Performance/Perf.EventWaitHandle.cs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,21 @@ namespace System.Threading.Tests
99
{
1010
public class Perf_EventWaitHandle
1111
{
12-
[Benchmark]
12+
[Benchmark(InnerIterationCount = 100_000)]
1313
public void Set_Reset()
1414
{
15-
foreach (var iteration in Benchmark.Iterations)
15+
using (EventWaitHandle are = new EventWaitHandle(false, EventResetMode.AutoReset))
1616
{
17-
using (EventWaitHandle are = new EventWaitHandle(false, EventResetMode.AutoReset))
18-
using (iteration.StartMeasurement())
17+
foreach (var iteration in Benchmark.Iterations)
1918
{
20-
are.Set(); are.Reset(); are.Set(); are.Reset();
21-
are.Set(); are.Reset(); are.Set(); are.Reset();
22-
are.Set(); are.Reset(); are.Set(); are.Reset();
23-
are.Set(); are.Reset(); are.Set(); are.Reset();
19+
using (iteration.StartMeasurement())
20+
{
21+
for (int i = 0; i < Benchmark.InnerIterationCount; i++)
22+
{
23+
are.Set();
24+
are.Reset();
25+
}
26+
}
2427
}
2528
}
2629
}

src/System.Threading/tests/Performance/Perf.Interlocked.cs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ namespace System.Threading.Tests
88
{
99
public class Perf_Interlocked
1010
{
11-
[Benchmark(InnerIterationCount = 1000)]
11+
private const int IterationCount = 10_000_000;
12+
13+
[Benchmark(InnerIterationCount = IterationCount)]
1214
public static void Increment_int()
1315
{
1416
int location = 0;
@@ -25,7 +27,7 @@ public static void Increment_int()
2527
}
2628
}
2729

28-
[Benchmark(InnerIterationCount = 1000)]
30+
[Benchmark(InnerIterationCount = IterationCount)]
2931
public static void Decrement_int()
3032
{
3133
int location = 0;
@@ -42,7 +44,7 @@ public static void Decrement_int()
4244
}
4345
}
4446

45-
[Benchmark(InnerIterationCount = 1000)]
47+
[Benchmark(InnerIterationCount = IterationCount)]
4648
public void Increment_long()
4749
{
4850
long location = 0;
@@ -59,7 +61,7 @@ public void Increment_long()
5961
}
6062
}
6163

62-
[Benchmark(InnerIterationCount = 1000)]
64+
[Benchmark(InnerIterationCount = IterationCount)]
6365
public void Decrement_long()
6466
{
6567
long location = 0;
@@ -76,7 +78,7 @@ public void Decrement_long()
7678
}
7779
}
7880

79-
[Benchmark(InnerIterationCount = 1000)]
81+
[Benchmark(InnerIterationCount = IterationCount)]
8082
public void Add_int()
8183
{
8284
int location = 0;
@@ -93,7 +95,7 @@ public void Add_int()
9395
}
9496
}
9597

96-
[Benchmark(InnerIterationCount = 1000)]
98+
[Benchmark(InnerIterationCount = IterationCount)]
9799
public void Add_long()
98100
{
99101
long location = 0;
@@ -110,7 +112,7 @@ public void Add_long()
110112
}
111113
}
112114

113-
[Benchmark(InnerIterationCount = 1000)]
115+
[Benchmark(InnerIterationCount = IterationCount)]
114116
public static void Exchange_int()
115117
{
116118
int location = 0;
@@ -128,7 +130,7 @@ public static void Exchange_int()
128130
}
129131
}
130132

131-
[Benchmark(InnerIterationCount = 1000)]
133+
[Benchmark(InnerIterationCount = IterationCount)]
132134
public static void Exchange_long()
133135
{
134136
long location = 0;
@@ -146,7 +148,7 @@ public static void Exchange_long()
146148
}
147149
}
148150

149-
[Benchmark(InnerIterationCount = 500)]
151+
[Benchmark(InnerIterationCount = IterationCount)]
150152
public static void CompareExchange_int()
151153
{
152154
int location = 0;
@@ -165,7 +167,7 @@ public static void CompareExchange_int()
165167
}
166168
}
167169

168-
[Benchmark(InnerIterationCount = 500)]
170+
[Benchmark(InnerIterationCount = IterationCount)]
169171
public static void CompareExchange_long()
170172
{
171173
long location = 0;

src/System.Threading/tests/Performance/Perf.Lock.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace System.Threading.Tests
99
{
1010
public class Perf_Lock
1111
{
12-
[Benchmark(InnerIterationCount = 100)]
12+
[Benchmark(InnerIterationCount = 2_000_000)]
1313
public static void ReaderWriterLockSlimPerf()
1414
{
1515
ReaderWriterLockSlim rwLock = new ReaderWriterLockSlim();

src/System.Threading/tests/Performance/Perf.Monitor.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ namespace System.Threading.Tests
88
{
99
public class Perf_Monitor
1010
{
11-
[Benchmark(InnerIterationCount = 250)]
11+
private const int IterationCount = 4_000_000;
12+
13+
[Benchmark(InnerIterationCount = IterationCount)]
1214
public static void EnterExit()
1315
{
1416
object sync = new object();
@@ -26,7 +28,7 @@ public static void EnterExit()
2628
}
2729
}
2830

29-
[Benchmark(InnerIterationCount = 100)]
31+
[Benchmark(InnerIterationCount = IterationCount)]
3032
public static void TryEnterExit()
3133
{
3234
object sync = new object();

src/System.Threading/tests/Performance/Perf.SpinLock.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ namespace System.Threading.Tests
88
{
99
public class Perf_SpinLock
1010
{
11-
[Benchmark(InnerIterationCount = 100)]
11+
private const int IterationCount = 1_000_000;
12+
13+
[Benchmark(InnerIterationCount = IterationCount)]
1214
public void EnterExit()
1315
{
1416
SpinLock spinLock = new SpinLock();
@@ -28,7 +30,7 @@ public void EnterExit()
2830
}
2931
}
3032

31-
[Benchmark(InnerIterationCount = 100)]
33+
[Benchmark(InnerIterationCount = IterationCount)]
3234
public void TryEnterExit()
3335
{
3436
SpinLock spinLock = new SpinLock();

src/System.Threading/tests/Performance/Perf.Volatile.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ namespace System.Threading.Tests
88
{
99
public class Perf_Volatile
1010
{
11-
[Benchmark(InnerIterationCount = 2000)]
11+
private const int IterationCount = 100_000_000;
12+
13+
[Benchmark(InnerIterationCount = IterationCount)]
1214
public void Read_double()
1315
{
1416
double location = 0;
@@ -25,7 +27,7 @@ public void Read_double()
2527
}
2628
}
2729

28-
[Benchmark(InnerIterationCount = 2000)]
30+
[Benchmark(InnerIterationCount = IterationCount)]
2931
public void Write_double()
3032
{
3133
double location = 0;

0 commit comments

Comments
 (0)