using Unity.Mathematics; using UnityEngine; using System.Diagnostics; public class MathematicsTests : MonoBehaviour { const int NUM_TESTS = 1_000_000; void Test() { Matrix4x4 identityMatrix4x4 = Matrix4x4.identity; float3x3 identityFloat3x3 = new float3x3(1, 0, 0, 0, 1, 0, 0, 0, 1); float4x4 identityFloat4x4 = new float4x4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); float vector3Duration, float3x3Duration, float4x4Duration; Vector3 myVector3 = Vector3.one; float3 myFloat3 = new float3(1f); var stopwatch = new Stopwatch(); stopwatch.Start(); for (int i = 0; i < NUM_TESTS; i++) { myVector3 = identityMatrix4x4.MultiplyPoint(myVector3); } stopwatch.Stop(); vector3Duration = stopwatch.ElapsedTicks / 10_000f; stopwatch = new Stopwatch(); stopwatch.Start(); for (int i = 0; i < NUM_TESTS; i++) { myFloat3 = math.mul(identityFloat3x3, myFloat3); } stopwatch.Stop(); float3x3Duration = stopwatch.ElapsedTicks / 10_000f; stopwatch = new Stopwatch(); stopwatch.Start(); for (int i = 0; i < NUM_TESTS; i++) { myFloat3 = math.mul(identityFloat4x4, new float4(myFloat3, 1f)).xyz; } stopwatch.Stop(); float4x4Duration = stopwatch.ElapsedTicks / 10_000f; UnityEngine.Debug.Log("Elapsed Vector3: " + vector3Duration + "ms\n" + "Elapsed float3x3: " + float3x3Duration + "ms\n" + "Elapsed float4x4: " + float4x4Duration + "ms\n"); } void OnEnable() => Test(); }