Skip to content

Commit bfc3f54

Browse files
More synchronized improvements.
1 parent 987fd4a commit bfc3f54

13 files changed

Lines changed: 1124 additions & 903 deletions

benchmarking/Benchmarks/CollectionBenchmark.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,17 @@ protected override IEnumerable<TimedResult> TestOnceInternal()
2121
for (int i = 0; i < TestSize; i++) c.Add(_items[i]);
2222
});
2323

24-
yield return TimedResult.Measure("Enumerate (8 times)", () =>
25-
{
26-
for (int i = 0; i < 8; ++i)
27-
{
28-
// ReSharper disable once NotAccessedVariable
29-
int x = 0;
30-
// ReSharper disable once LoopCanBeConvertedToQuery
31-
foreach (T _ in c) { x++; }
32-
Debug.Assert(x == TestSize);
33-
}
34-
});
24+
//yield return TimedResult.Measure("Enumerate (8 times)", () =>
25+
//{
26+
// for (int i = 0; i < 8; ++i)
27+
// {
28+
// // ReSharper disable once NotAccessedVariable
29+
// int x = 0;
30+
// // ReSharper disable once LoopCanBeConvertedToQuery
31+
// foreach (T _ in c) { x++; }
32+
// Debug.Assert(x == TestSize);
33+
// }
34+
//});
3535

3636
yield return TimedResult.Measure(".Contains(item)", () =>
3737
{

benchmarking/Benchmarks/CollectionParallelBenchmark.cs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,27 @@ protected override IEnumerable<TimedResult> TestOnceInternal()
2020
yield return TimedResult.Measure("Fill (.Add(item)) (In Parallel)",
2121
() => Parallel.For(0, TestSize, i => c.Add(_items[i])));
2222

23-
yield return TimedResult.Measure("Enumerate (8 times)", () =>
24-
{
25-
for (int i = 0; i < 8; ++i)
26-
{
27-
// ReSharper disable once NotAccessedVariable
28-
int x = 0;
29-
// ReSharper disable once LoopCanBeConvertedToQuery
30-
foreach (T _ in c) { x++; }
31-
Debug.Assert(x == TestSize);
32-
}
33-
});
34-
35-
// It's obvious to note that you have to 'lock' a collection or acquire a 'snapshot' before enumerating.
36-
yield return TimedResult.Measure("Enumerate (8 times) (In Parallel)",
37-
() =>
38-
{
39-
for (int i = 0; i < 8; ++i)
40-
{
41-
Parallel.ForEach(c, _ => { });
42-
}
43-
});
23+
//yield return TimedResult.Measure("Enumerate (8 times)", () =>
24+
//{
25+
// for (int i = 0; i < 8; ++i)
26+
// {
27+
// // ReSharper disable once NotAccessedVariable
28+
// int x = 0;
29+
// // ReSharper disable once LoopCanBeConvertedToQuery
30+
// foreach (T _ in c) { x++; }
31+
// Debug.Assert(x == TestSize);
32+
// }
33+
//});
34+
35+
//// It's obvious to note that you have to 'lock' a collection or acquire a 'snapshot' before enumerating.
36+
//yield return TimedResult.Measure("Enumerate (8 times) (In Parallel)",
37+
// () =>
38+
// {
39+
// for (int i = 0; i < 8; ++i)
40+
// {
41+
// Parallel.ForEach(c, _ => { });
42+
// }
43+
// });
4444

4545
yield return TimedResult.Measure(".Contains(item) (In Parallel)",
4646
() => Parallel.For(0, TestSize * 2, i => { bool _ = c.Contains(_items[i]); }));

benchmarking/Benchmarks/DictionaryParallelBenchmark.cs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -36,26 +36,26 @@ protected override IEnumerable<TimedResult> TestOnceInternal()
3636
Debug.Assert(c[i] == _items[i].Value);
3737
#endif
3838

39-
yield return TimedResult.Measure("Enumerate (8 times)", () =>
40-
{
41-
for (int i = 0; i < 8; ++i)
42-
{
43-
// ReSharper disable once NotAccessedVariable
44-
int x = 0;
45-
// ReSharper disable once LoopCanBeConvertedToQuery
46-
foreach (var _ in c) { x++; }
47-
Debug.Assert(x == TestSize);
48-
}
49-
});
39+
//yield return TimedResult.Measure("Enumerate (8 times)", () =>
40+
//{
41+
// for (int i = 0; i < 8; ++i)
42+
// {
43+
// // ReSharper disable once NotAccessedVariable
44+
// int x = 0;
45+
// // ReSharper disable once LoopCanBeConvertedToQuery
46+
// foreach (var _ in c) { x++; }
47+
// Debug.Assert(x == TestSize);
48+
// }
49+
//});
5050

51-
yield return TimedResult.Measure("Enumerate (8 times) (In Parallel)",
52-
() =>
53-
{
54-
for (int i = 0; i < 8; ++i)
55-
{
56-
Parallel.ForEach(c, _ => { });
57-
}
58-
});
51+
//yield return TimedResult.Measure("Enumerate (8 times) (In Parallel)",
52+
// () =>
53+
// {
54+
// for (int i = 0; i < 8; ++i)
55+
// {
56+
// Parallel.ForEach(c, _ => { });
57+
// }
58+
// });
5959

6060
yield return TimedResult.Measure(".Contains(item) (In Parallel)",
6161
() => Parallel.For(0, testSize * 2, i =>

0 commit comments

Comments
 (0)