public static void Test() { var random = new Random(4); var timer = new Stopwatch(); var symmetricVectorSandwichTime = 0.0; var symmetricWideVectorSandwichTime = 0.0; var triangularWideVectorSandwichTime = 0.0; var symmetricWide2x3SandwichTime = 0.0; var triangularWide2x3SandwichTime = 0.0; var symmetricSkewSandwichTime = 0.0; var symmetricWideSkewSandwichTime = 0.0; var triangularWideSkewSandwichTime = 0.0; var symmetricRotationSandwichTime = 0.0; var symmetricWideRotationSandwichTime = 0.0; var triangularWideRotationSandwichTime = 0.0; var symmetricInvertTime = 0.0; var symmetricWideInvertTime = 0.0; var triangularWideInvertTime = 0.0; for (int i = 0; i < 1000; ++i) { var axis = Vector3.Normalize(new Vector3((float)random.NextDouble() * 2 - 1, (float)random.NextDouble() * 2 - 1, (float)random.NextDouble() * 2 - 1)); Vector3Wide.CreateFrom(ref axis, out var axisWide); var rotation = Matrix3x3.CreateFromAxisAngle(axis, (float)random.NextDouble()); Matrix3x3Wide rotationWide; Vector3Wide.CreateFrom(ref rotation.X, out rotationWide.X); Vector3Wide.CreateFrom(ref rotation.Y, out rotationWide.Y); Vector3Wide.CreateFrom(ref rotation.Z, out rotationWide.Z); var m2x3Wide = new Matrix2x3Wide() { X = axisWide, Y = new Vector3Wide { X = -axisWide.Y, Y = axisWide.Z, Z = axisWide.X } }; var triangular = new Triangular3x3 { M11 = (float)random.NextDouble() * 2 + 1, M21 = (float)random.NextDouble() * 1 + 1, M22 = (float)random.NextDouble() * 2 + 1, M31 = (float)random.NextDouble() * 1 + 1, M32 = (float)random.NextDouble() * 1 + 1, M33 = (float)random.NextDouble() * 2 + 1, }; Triangular3x3Wide triangularWide; triangularWide.M11 = new Vector <float>(triangular.M11); triangularWide.M21 = new Vector <float>(triangular.M21); triangularWide.M22 = new Vector <float>(triangular.M22); triangularWide.M31 = new Vector <float>(triangular.M31); triangularWide.M32 = new Vector <float>(triangular.M32); triangularWide.M33 = new Vector <float>(triangular.M33); var symmetric = new Matrix3x3 { X = new Vector3(triangular.M11, triangular.M21, triangular.M31), Y = new Vector3(triangular.M21, triangular.M22, triangular.M32), Z = new Vector3(triangular.M31, triangular.M32, triangular.M33), }; Matrix3x3Wide symmetricWide; Vector3Wide.CreateFrom(ref symmetric.X, out symmetricWide.X); Vector3Wide.CreateFrom(ref symmetric.Y, out symmetricWide.Y); Vector3Wide.CreateFrom(ref symmetric.Z, out symmetricWide.Z); var symmetricVectorSandwich = new SymmetricVectorSandwich() { v = axis, symmetric = symmetric }; var symmetricWideVectorSandwich = new SymmetricWideVectorSandwich() { v = axisWide, symmetric = symmetricWide }; var triangularWideVectorSandwich = new TriangularWideVectorSandwich() { v = axisWide, triangular = triangularWide }; var symmetricWide2x3Sandwich = new SymmetricWide2x3Sandwich() { m = m2x3Wide, symmetric = symmetricWide }; var triangularWide2x3Sandwich = new TriangularWide2x3Sandwich() { m = m2x3Wide, triangular = triangularWide }; var symmetricSkewSandwich = new SymmetricSkewSandwich() { v = axis, symmetric = symmetric }; var symmetricWideSkewSandwich = new SymmetricWideSkewSandwich() { v = axisWide, symmetric = symmetricWide }; var triangularWideSkewSandwich = new TriangularWideSkewSandwich() { v = axisWide, triangular = triangularWide }; var symmetricSandwich = new SymmetricRotationSandwich() { rotation = rotation, symmetric = symmetric }; var symmetricWideSandwich = new SymmetricRotationSandwichWide() { rotation = rotationWide, symmetric = symmetricWide }; var triangularWideSandwich = new TriangularRotationSandwichWide() { rotation = rotationWide, triangular = triangularWide }; var symmetricInvert = new SymmetricInvert() { symmetric = symmetric }; var symmetricWideInvert = new SymmetricInvertWide() { symmetric = symmetricWide }; var triangularWideInvert = new TriangularInvertWide() { triangular = triangularWide }; const int innerIterations = 100000; symmetricVectorSandwichTime += TimeTest(innerIterations, ref symmetricVectorSandwich); symmetricWideVectorSandwichTime += TimeTest(innerIterations, ref symmetricWideVectorSandwich); triangularWideVectorSandwichTime += TimeTest(innerIterations, ref triangularWideVectorSandwich); symmetricWide2x3SandwichTime += TimeTest(innerIterations, ref symmetricWide2x3Sandwich); triangularWide2x3SandwichTime += TimeTest(innerIterations, ref triangularWide2x3Sandwich); symmetricSkewSandwichTime += TimeTest(innerIterations, ref symmetricSkewSandwich); symmetricWideSkewSandwichTime += TimeTest(innerIterations, ref symmetricWideSkewSandwich); triangularWideSkewSandwichTime += TimeTest(innerIterations, ref triangularWideSkewSandwich); symmetricRotationSandwichTime += TimeTest(innerIterations, ref symmetricSandwich); symmetricWideRotationSandwichTime += TimeTest(innerIterations, ref symmetricWideSandwich); triangularWideRotationSandwichTime += TimeTest(innerIterations, ref triangularWideSandwich); symmetricInvertTime += TimeTest(innerIterations, ref symmetricInvert); symmetricWideInvertTime += TimeTest(innerIterations, ref symmetricWideInvert); triangularWideInvertTime += TimeTest(innerIterations, ref triangularWideInvert); Compare(symmetricVectorSandwich.result, ref symmetricWideVectorSandwich.result); Compare(symmetricVectorSandwich.result, ref triangularWideVectorSandwich.result); Compare(ref symmetricWide2x3Sandwich.result, ref triangularWide2x3Sandwich.result); Compare(ref symmetricSkewSandwich.result, ref symmetricWideSkewSandwich.result); Compare(ref symmetricSkewSandwich.result, ref triangularWideSkewSandwich.result); Compare(ref symmetricSandwich.result, ref symmetricWideSandwich.result); Compare(ref symmetricSandwich.result, ref triangularWideSandwich.result); Compare(ref symmetricInvert.result, ref symmetricWideInvert.result); Compare(ref symmetricInvert.result, ref triangularWideInvert.result); } Console.WriteLine($"Symmetric vector sandwich: {symmetricVectorSandwichTime}"); Console.WriteLine($"Symmetric wide vector sandwich: {symmetricWideVectorSandwichTime}"); Console.WriteLine($"Triangular wide vector sandwich: {triangularWideVectorSandwichTime}"); Console.WriteLine($"Symmetric wide 2x3 sandwich: {symmetricWide2x3SandwichTime}"); Console.WriteLine($"Triangular wide 2x3 sandwich: {triangularWide2x3SandwichTime}"); Console.WriteLine($"Symmetric skew sandwich: {symmetricSkewSandwichTime}"); Console.WriteLine($"Symmetric wide skew sandwich: {symmetricWideSkewSandwichTime}"); Console.WriteLine($"Triangular wide skew sandwich: {triangularWideSkewSandwichTime}"); Console.WriteLine($"Symmetric rotation sandwich: {symmetricRotationSandwichTime}"); Console.WriteLine($"Symmetric wide rotation sandwich: {symmetricWideRotationSandwichTime}"); Console.WriteLine($"Triangular wide rotation sandwich: {triangularWideRotationSandwichTime}"); Console.WriteLine($"Symmetric invert: {symmetricInvertTime}"); Console.WriteLine($"Symmetric wide invert: {symmetricWideInvertTime}"); Console.WriteLine($"Triangular wide invert: {triangularWideInvertTime}"); }