Skip to content

Commit

Permalink
test: refine lake benchmark
Browse files Browse the repository at this point in the history
Add a benchmark test using Lake Superior as input, providing a more generalized test case compared to the previous refinement benchmark.
  • Loading branch information
andywiecko committed Nov 13, 2024
1 parent b0088f3 commit 0fea9d0
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions Tests/TriangulatorBenchmarkTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,69 @@ public void RefineMeshBenchmarkTest((float area, int N) input)
Unity.Jobs.LowLevel.Unsafe.JobsUtility.JobDebuggerEnabled = debuggerInitialValue;
}

private static readonly TestCaseData[] refineMeshLakeBenchmarkTestData =
{
new(00.00f, 100),
new(05.00f, 100),
new(10.00f, 100),
new(15.00f, 100),
new(20.00f, 100),
new(25.00f, 100),
new(28.00f, 100),
new(30.00f, 100),
new(31.50f, 100),
new(33.00f, 100),
new(33.50f, 100),
new(33.70f, 100),
new(33.72f, 100),
new(33.73f, 100),
//new(33.75f, 1), // Limit
};

[Test, TestCaseSource(nameof(refineMeshLakeBenchmarkTestData))]
public void RefineMeshLakeBenchmarkTest(float angle, int N)
{
var debuggerInitialValue = Unity.Jobs.LowLevel.Unsafe.JobsUtility.JobDebuggerEnabled;
Unity.Jobs.LowLevel.Unsafe.JobsUtility.JobDebuggerEnabled = false;

using var positions = new NativeArray<float2>(LakeSuperior.Points, Allocator.Persistent);
using var constraintEdges = new NativeArray<int>(LakeSuperior.Constraints, Allocator.Persistent);
using var holeSeeds = new NativeArray<float2>(LakeSuperior.Holes, Allocator.Persistent);
using var triangulator = new Triangulator<float2>(1024 * 1024, Allocator.Persistent)
{
Settings =
{
ValidateInput = false,
RefineMesh = true,
RestoreBoundary = true,
RefinementThresholds =
{
Area = 100f,
Angle = math.radians(angle),
}
},
Input =
{
Positions = positions,
ConstraintEdges = constraintEdges,
HoleSeeds = holeSeeds,
}
};

var stopwatch = Stopwatch.StartNew();
for (int i = 0; i < N; i++)
{
triangulator.Run();
}
stopwatch.Stop();

triangulator.Draw();

UnityEngine.Debug.Log($"{triangulator.Output.Triangles.Length / 3} {stopwatch.Elapsed.TotalMilliseconds / N}");

Unity.Jobs.LowLevel.Unsafe.JobsUtility.JobDebuggerEnabled = debuggerInitialValue;
}

private static TestCaseData PlantingHolesCase(int n, int N) => new((n, N)) { TestName = $"Holes: {n * n} (N: {N})" };

private static readonly TestCaseData[] plantingAutoHolesBenchmarkTestData =
Expand Down

0 comments on commit 0fea9d0

Please sign in to comment.