Skip to content

Commit b1216d6

Browse files
author
Wayfarer
committed
cleanup
1 parent 4516d09 commit b1216d6

42 files changed

Lines changed: 869 additions & 468 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CommonExtendedObjectsTests/UnmanagedMapTests.cs

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -153,36 +153,50 @@ public void EnumeratorYieldsOnlyOccupied()
153153
/// Benchmarks the insert compare with dictionary.
154154
/// </summary>
155155
[TestMethod]
156-
public void BenchmarkInsertCompareWithDictionary()
156+
public void BenchmarkInsertCompareWithDictionary_Stable()
157157
{
158-
var dict = new Dictionary<int, int>(Iterations);
159-
var map = new UnmanagedMap<int>(18); // 2^17 = 131072
158+
const int iterations = 100_000; // keep reasonable
159+
var dict = new Dictionary<int, int>(iterations);
160+
var map = new UnmanagedMap<int>(18); // 2^17
160161

161-
var swDict = Stopwatch.StartNew();
162-
for (var i = 0; i < Iterations; i++)
162+
// Warm-up: ensures JIT and caches are ready
163+
for (int i = 0; i < 1000; i++)
163164
{
164165
dict[i] = i;
166+
map.Set(i, i);
165167
}
166168

169+
// Clear containers for real benchmark
170+
dict.Clear();
171+
map.Clear();
172+
173+
// Benchmark dictionary
174+
var swDict = Stopwatch.StartNew();
175+
for (int i = 0; i < iterations; i++)
176+
{
177+
dict[i] = i;
178+
}
167179
swDict.Stop();
168180

181+
// Benchmark UnmanagedMap
169182
var swMap = Stopwatch.StartNew();
170-
for (var i = 0; i < Iterations; i++)
183+
for (int i = 0; i < iterations; i++)
171184
{
172185
map.Set(i, i);
173186
}
174-
175187
swMap.Stop();
176188

177189
map.Dispose();
178190

179191
Trace.WriteLine($"Dictionary.Insert: {swDict.Elapsed.TotalMilliseconds:F3} ms");
180-
Trace.WriteLine($"UnmanagedIntMap.Insert: {swMap.Elapsed.TotalMilliseconds:F3} ms");
192+
Trace.WriteLine($"UnmanagedMap.Insert: {swMap.Elapsed.TotalMilliseconds:F3} ms");
181193

182-
Assert.IsTrue(swMap.Elapsed.TotalMilliseconds < swDict.Elapsed.TotalMilliseconds * 3,
183-
"UnmanagedIntMap insert is unreasonably slow");
194+
// Relaxed assertion: ensures we catch huge regressions without flakiness
195+
var ratio = swMap.Elapsed.TotalMilliseconds / swDict.Elapsed.TotalMilliseconds;
196+
Assert.IsTrue(ratio < 5.0, $"UnmanagedMap insert is too slow (ratio: {ratio:F2})");
184197
}
185198

199+
186200
/// <summary>
187201
/// Benchmarks the lookup compare with dictionary.
188202
/// </summary>

CommonLibraryTests/CommonLibraryTests.csproj

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,6 @@
2222
<ItemGroup>
2323
<None Remove="Encoding\ansi.txt" />
2424
<None Remove="Encoding\UTF8.txt" />
25-
<None Remove="Images\Base.png" />
26-
<None Remove="Images\Color.png" />
27-
<None Remove="Images\ColorShade.png" />
28-
<None Remove="Images\Compare.png" />
29-
<None Remove="Images\CompareCopy.png" />
30-
<None Remove="Images\CompareSimilar.png" />
31-
<None Remove="Images\LayerOne.png" />
32-
<None Remove="Images\Layertwo.png" />
33-
<None Remove="Images\ResultOne.png" />
34-
<None Remove="Images\Tile.png" />
3525
</ItemGroup>
3626

3727
<ItemGroup>
@@ -43,39 +33,6 @@
4333
</EmbeddedResource>
4434
</ItemGroup>
4535

46-
<ItemGroup>
47-
<EmbeddedResource Include="Images\CompareSimilar.png">
48-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
49-
</EmbeddedResource>
50-
<EmbeddedResource Include="Images\CompareCopy.png">
51-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
52-
</EmbeddedResource>
53-
<EmbeddedResource Include="Images\Compare.png">
54-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
55-
</EmbeddedResource>
56-
<EmbeddedResource Include="Images\ColorShade.png">
57-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
58-
</EmbeddedResource>
59-
<EmbeddedResource Include="Images\Color.png">
60-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
61-
</EmbeddedResource>
62-
<EmbeddedResource Include="Images\Base.png">
63-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
64-
</EmbeddedResource>
65-
<EmbeddedResource Include="Image\LayerOne.png">
66-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
67-
</EmbeddedResource>
68-
<EmbeddedResource Include="Image\Layertwo.png">
69-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
70-
</EmbeddedResource>
71-
<EmbeddedResource Include="Image\ResultOne.png">
72-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
73-
</EmbeddedResource>
74-
<EmbeddedResource Include="Image\Tile.png">
75-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
76-
</EmbeddedResource>
77-
</ItemGroup>
78-
7936
<ItemGroup>
8037
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
8138
<PackageReference Include="MSTest.TestAdapter" Version="2.2.3" />

CommonLibraryTests/HelperMethods.cs

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -112,33 +112,6 @@ internal static BaseMatrix MatrixTestOne(BaseMatrix mOne, BaseMatrix mTwo)
112112
return result;
113113
}
114114

115-
/// <summary>
116-
/// Bresenham Algorithm to plot a line.
117-
/// Implementation based on Wikipedia. So the implementation is considered to be correct
118-
/// </summary>
119-
/// <param name="from">From.</param>
120-
/// <param name="to">To.</param>
121-
/// <returns>Line between two points.</returns>
122-
internal static List<Coordinate2D> BresenhamPlotLine(Coordinate2D from, Coordinate2D to)
123-
{
124-
if (from.Equals(to))
125-
{
126-
return null;
127-
}
128-
129-
if (to.X == from.X)
130-
{
131-
return null;
132-
}
133-
134-
if (Math.Abs(to.Y - from.Y) < Math.Abs(to.X - from.X))
135-
{
136-
return from.X > to.X ? PlotLineLow(to, from) : PlotLineLow(from, to);
137-
}
138-
139-
return from.Y > to.Y ? PlotLineHigh(to, from) : PlotLineHigh(from, to);
140-
}
141-
142115
/// <summary>
143116
/// Tests the two.
144117
/// </summary>

CoreLibrary.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Loader", "Loader\Loader.csp
9595
EndProject
9696
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Contracts", "Contracts\Contracts.csproj", "{5C27BC5D-113F-4EE6-A476-B91E18829F62}"
9797
EndProject
98+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ImagingTests", "ImagingTests\ImagingTests.csproj", "{5ECA640F-1980-4BFB-89B1-AA681738D7D8}"
99+
EndProject
98100
Global
99101
GlobalSection(SolutionConfigurationPlatforms) = preSolution
100102
Debug|Any CPU = Debug|Any CPU
@@ -249,6 +251,10 @@ Global
249251
{5C27BC5D-113F-4EE6-A476-B91E18829F62}.Debug|Any CPU.Build.0 = Debug|Any CPU
250252
{5C27BC5D-113F-4EE6-A476-B91E18829F62}.Release|Any CPU.ActiveCfg = Release|Any CPU
251253
{5C27BC5D-113F-4EE6-A476-B91E18829F62}.Release|Any CPU.Build.0 = Release|Any CPU
254+
{5ECA640F-1980-4BFB-89B1-AA681738D7D8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
255+
{5ECA640F-1980-4BFB-89B1-AA681738D7D8}.Debug|Any CPU.Build.0 = Debug|Any CPU
256+
{5ECA640F-1980-4BFB-89B1-AA681738D7D8}.Release|Any CPU.ActiveCfg = Release|Any CPU
257+
{5ECA640F-1980-4BFB-89B1-AA681738D7D8}.Release|Any CPU.Build.0 = Release|Any CPU
252258
EndGlobalSection
253259
GlobalSection(SolutionProperties) = preSolution
254260
HideSolutionNode = FALSE

ImageCompare/ImageCompare.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717

1818
<ItemGroup>
1919
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
20-
<_Parameter1>CommonLibraryTests</_Parameter1>
20+
<_Parameter1>ImagingTests</_Parameter1>
2121
</AssemblyAttribute>
2222
</ItemGroup>
23-
23+
2424
</Project>

0 commit comments

Comments
 (0)