Skip to content

Commit

Permalink
test: delaunay benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
andywiecko committed Sep 11, 2023
1 parent e3b9e5e commit c91bba2
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions Tests/TriangulatorEditorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1631,6 +1631,7 @@ public void RefineMeshBenchmarkTest((float area, int N) input)
RefineMesh = true,
ConstrainEdges = false,
RestoreBoundary = false,
ValidateInput = false,
MinimumArea = area,
MaximumArea = area,
},
Expand All @@ -1644,5 +1645,63 @@ public void RefineMeshBenchmarkTest((float area, int N) input)

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

static TestCaseData DelaunayCase(int count, int N) => new((count: count, N: N))
{
TestName = $"Points: {count * count}"
};
private static readonly TestCaseData[] delaunayBenchmarkTestData =
{
DelaunayCase(count: 10, N: 100),
DelaunayCase(count: 20, N: 100),
DelaunayCase(count: 30, N: 100),
DelaunayCase(count: 40, N: 100),
DelaunayCase(count: 50, N: 100),
DelaunayCase(count: 60, N: 10),
DelaunayCase(count: 70, N: 10),
DelaunayCase(count: 80, N: 10),
DelaunayCase(count: 90, N: 10),
DelaunayCase(count: 100, N: 10),
};

[Test, TestCaseSource(nameof(delaunayBenchmarkTestData)), Explicit]
public void DelaunayBenchmarkTest((int count, int N) input)
{
var (count, N) = input;
var debuggerInitialValue = Unity.Jobs.LowLevel.Unsafe.JobsUtility.JobDebuggerEnabled;
Unity.Jobs.LowLevel.Unsafe.JobsUtility.JobDebuggerEnabled = false;

var points = new List<float2>(count * count);
for (int i = 0; i < count; i++)
{
for (int j = 0; j < count; j++)
{
var p = math.float2(i / (float)(count - 1), j / (float)(count - 1));
points.Add(p);
}
}

using var positions = new NativeArray<float2>(points.ToArray(), Allocator.Persistent);

var stopwatch = Stopwatch.StartNew();
using var triangulator = new Triangulator(capacity: 64 * 1024, Allocator.Persistent)
{
Input = { Positions = positions },
Settings = {
RefineMesh = false,
ConstrainEdges = false,
RestoreBoundary = false,
ValidateInput = false,
},
};

var dependencies = default(JobHandle);
for (int i = 0; i < N; i++) dependencies = triangulator.Schedule(dependencies);
dependencies.Complete();
stopwatch.Stop();
UnityEngine.Debug.Log($"{count * count} {stopwatch.Elapsed.TotalMilliseconds / N}");

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

0 comments on commit c91bba2

Please sign in to comment.