Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,11 @@ public void RunWithEntryCheck()

private void ProcessingStep(int stepNumber)
{
int emptyHits = 0;
for (int iteration = 0; iteration < MaxIterations; iteration++)
{
var entryKey = iteration % MaxStateEntries;

if (CheckStateIsEmpty())
{
emptyHits++;
}
CheckStateIsEmpty();

_sharedState.AddOrUpdate(
entryKey,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
public class NaiveExampleUnsized
{
public const int MaxIterations = 100;
public const int MaxStateEntries = 10;
public const int ProcessingSteps = 40;
private Dictionary<int, int> _sharedState = new();

public void Run()
{
Parallel.ForEach(Enumerable.Range(0, ProcessingSteps), ProcessingStep);

PrintState();
}

private void ProcessingStep(int stepNumber)
{
for (int iteration = 0; iteration < MaxIterations; iteration++)
{
var entryKey = iteration % MaxStateEntries;
if (!_sharedState.TryGetValue(entryKey, out int entryValue))
{
entryValue = 0;
}
_sharedState[entryKey] = entryValue + 1;
}
}

private void PrintState()
{
foreach (var entry in _sharedState)
{
Console.WriteLine($"{entry.Key}\t{entry.Value}");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@

try
{
new NaiveExampleUnsized().Run();
}
catch (AggregateException ex)
{
Console.WriteLine(ex);
}

Console.WriteLine(new string('=', 20));

new NaiveExample().Run();

Console.WriteLine(new string('=', 20));
Expand All @@ -15,9 +26,11 @@

Console.WriteLine(new string('=', 20));

Console.WriteLine("Running ContentionExample, this takes a few seconds...");
new ContentionExample().Run();

Console.WriteLine(new string('=', 20));

Console.WriteLine("Running MemoryLeakExample, this takes a few seconds...");
new MemoryLeakExample().Run();

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Tests
public class ContentionExampleIntegrationTest
{
private int expectedEntryValue = ContentionExample.ProcessingSteps * ContentionExample.MaxIterations / ContentionExample.MaxStateEntries;
private ContentionExample sut = new();
private ContentionExample sut;

[SetUp]
public void SetUp()
Expand All @@ -30,7 +30,7 @@ public void WhenRunSecondVariant_ThenAllStateEntriesHaveExpectedValue()
}

[Test]
public void WhenBothVariantsRun_ThenTheSecondVariantTakesMoreTime()
public void WhenBothVariantsRun_ThenTheSecondVariantTakesMoreTime_Live()
{
ContentionExample firstVariant = new();
ContentionExample secondVariant = new();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public class MemoryLeakExampleIntegrationTest
{
private int expectedEntryValue = MemoryLeakExample.ProcessingSteps * MemoryLeakExample.MaxIterations / MemoryLeakExample.MaxStateEntries;

private MemoryLeakExample sut = new();
private MemoryLeakExample sut;

[SetUp]
public void SetUp()
Expand Down
12 changes: 6 additions & 6 deletions collections-csharp/ConcurrentDictionary/Tests/Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
<PackageReference Include="NUnit.Analyzers" Version="3.3.0" />
<PackageReference Include="coverlet.collector" Version="3.1.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.10.1" />
<PackageReference Include="NUnit" Version="4.6.1" />
<PackageReference Include="NUnit3TestAdapter" Version="6.3.0" />
<PackageReference Include="NUnit.Analyzers" Version="4.15.0" />
<PackageReference Include="coverlet.collector" Version="10.0.1" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading