Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: constraint triangulation benchmark #62

Merged
merged 1 commit into from
Sep 24, 2023
Merged
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
63 changes: 63 additions & 0 deletions Tests/TriangulatorEditorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1844,5 +1844,68 @@ public void DelaunayBenchmarkTest((int count, int N) input)

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

private static readonly TestCaseData[] constraintBenchmarkTestData = Enumerable
.Range(0, 80)
.Select(i => new TestCaseData((100, 3 * (i + 1))))
.ToArray();

[Test, TestCaseSource(nameof(constraintBenchmarkTestData)), Explicit]
public void ConstraintBenchmarkTest((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);
}
}

var offset = points.Count;
var constraints = new List<int>(N + 1);
for (int i = 0; i < N; i++)
{
var phi = 2 * math.PI / N * i + 0.1452f;
var p = 0.2f * math.float2(math.cos(phi), math.sin(phi)) + 0.5f;
points.Add(p);
constraints.Add(offset + i);
constraints.Add(offset + (i + 1) % N);
}

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

var stopwatch = Stopwatch.StartNew();
using var triangulator = new Triangulator(capacity: count * count + N, Allocator.Persistent)
{
Input = { Positions = positions, ConstraintEdges = constraintEdges },
Settings = {
RefineMesh = false,
ConstrainEdges = true,
RestoreBoundary = false,
ValidateInput = false
},
};

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

// NOTE: Uncomment this to write all the test cases into a file.
//using var writer = new System.IO.StreamWriter("tmp.txt", true);
//writer.WriteLine(log);

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