点像と畳み込みの割り当ての試験を最小値の測定で判定する

このコミットが含まれているのは:
routersys committed 2026-10-09 13:20:59 +09:00
1 親 368b52668a
コミット defceb10dd
5ファイル変更
+62 -25

検索条件に一致するファイルはありません

+24
ファイルの表示
@@ -0,0 +1,24 @@
namespace WaveOptics.Tests;
internal static class AllocationProbe
{
public static long MinimumAllocatedBytes(Action action, int rounds)
{
var minimum = long.MaxValue;
for (var round = 0; round < rounds; round++)
{
var before = GC.GetAllocatedBytesForCurrentThread();
action();
minimum = Math.Min(minimum, GC.GetAllocatedBytesForCurrentThread() - before);
}
return minimum;
}
public static void Settle()
{
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
}
}
+5 -5
ファイルの表示
@@ -242,13 +242,13 @@ public sealed class ChromaticKernelSamplerTests
var red = new double[area];
var green = new double[area];
var blue = new double[area];
Assert.True(sampler.TrySample(in specification, mode, WaveOpticsQuality.High, red, green, blue));
void Sample() => Assert.True(sampler.TrySample(in specification, mode, WaveOpticsQuality.High, red, green, blue));
var before = GC.GetAllocatedBytesForCurrentThread();
for (var round = 0; round < 3; round++)
Assert.True(sampler.TrySample(in specification, mode, WaveOpticsQuality.High, red, green, blue));
Sample();
Sample();
AllocationProbe.Settle();
Assert.Equal(0, GC.GetAllocatedBytesForCurrentThread() - before);
Assert.Equal(0, AllocationProbe.MinimumAllocatedBytes(Sample, 8));
}
[Theory]
+11 -7
ファイルの表示
@@ -129,15 +129,19 @@ public sealed class FraunhoferKernelSamplerTests
public void AWarmSamplerAllocatesNoManagedMemory()
{
var specification = PsfSpecification.Of(Descriptor());
sampler.TrySample(in specification, kernel.AsSpan(0, 31 * 31));
var before = GC.GetAllocatedBytesForCurrentThread();
for (var step = 0; step < 4; step++)
void SampleEveryDefocusStep()
{
var animated = specification with { Aberration = new WavefrontAberration(defocusWaves: step * 0.25) };
sampler.TrySample(in animated, kernel.AsSpan(0, 31 * 31));
for (var step = 0; step < 4; step++)
{
var animated = specification with { Aberration = new WavefrontAberration(defocusWaves: step * 0.25) };
sampler.TrySample(in animated, kernel.AsSpan(0, 31 * 31));
}
}
Assert.Equal(0, GC.GetAllocatedBytesForCurrentThread() - before);
SampleEveryDefocusStep();
SampleEveryDefocusStep();
AllocationProbe.Settle();
Assert.Equal(0, AllocationProbe.MinimumAllocatedBytes(SampleEveryDefocusStep, 16));
}
}
+11 -6
ファイルの表示
@@ -253,14 +253,19 @@ public sealed class WaveOpticsChromaticPipelineTests
pipeline.RenderVisible(warmRect, in parameters);
}
var before = GC.GetAllocatedBytesForCurrentThread();
for (var frame = 0; frame < 8; frame++)
void RenderFrames()
{
pipeline.Simulate(sources[frame % 2], Width, Height, 0, 0, Width, Height, in parameters);
pipeline.TryGetVisibleBounds(Width, Height, in parameters, out var rect);
pipeline.RenderVisible(rect, in parameters);
for (var frame = 0; frame < 8; frame++)
{
pipeline.Simulate(sources[frame % 2], Width, Height, 0, 0, Width, Height, in parameters);
pipeline.TryGetVisibleBounds(Width, Height, in parameters, out var rect);
pipeline.RenderVisible(rect, in parameters);
}
}
Assert.Equal(0L, GC.GetAllocatedBytesForCurrentThread() - before);
RenderFrames();
AllocationProbe.Settle();
Assert.Equal(0L, AllocationProbe.MinimumAllocatedBytes(RenderFrames, 8));
}
}
+11 -7
ファイルの表示
@@ -157,16 +157,20 @@ public sealed class WaveOpticsCpuPipelineTests
for (var warmUp = 0; warmUp < 4; warmUp++)
RenderFrame(pipeline, sources[warmUp % 2], 96, 96, 16, in parameters, out _);
var before = GC.GetAllocatedBytesForCurrentThread();
for (var frame = 0; frame < 8; frame++)
void RenderFrames()
{
pipeline.Simulate(sources[frame % 2], 128, 128, 16, 16, 96, 96, in parameters);
pipeline.TryGetVisibleBounds(128, 128, in parameters, out var rect);
pipeline.RenderVisible(rect, in parameters);
for (var frame = 0; frame < 8; frame++)
{
pipeline.Simulate(sources[frame % 2], 128, 128, 16, 16, 96, 96, in parameters);
pipeline.TryGetVisibleBounds(128, 128, in parameters, out var rect);
pipeline.RenderVisible(rect, in parameters);
}
}
var allocated = GC.GetAllocatedBytesForCurrentThread() - before;
Assert.Equal(0L, allocated);
RenderFrames();
AllocationProbe.Settle();
Assert.Equal(0L, AllocationProbe.MinimumAllocatedBytes(RenderFrames, 8));
}
[Fact]