public void BenchmarkAdaptiveInvert() { var swf = new Stopwatch(); var swd = new Stopwatch(); var deltas = new List <decimal>(); foreach (var m in testCases) { Matrix3x3 testCase = m; for (int i = 0; i < 10000; i++) { FloatMatrix3x3 floatMatrix = MathConverter.Convert(testCase); FloatMatrix3x3 expected; swf.Start(); FloatMatrix3x3.AdaptiveInvert(ref floatMatrix, out expected); swf.Stop(); Matrix3x3 actual; swd.Start(); Matrix3x3.AdaptiveInvert(ref testCase, out actual); swd.Stop(); foreach (decimal delta in GetDeltas(expected, actual)) { deltas.Add(delta); } } } output.WriteLine("Max error: {0} ({1} times precision)", deltas.Max(), deltas.Max() / Fix64.Precision); output.WriteLine("Average precision: {0} ({1} times precision)", deltas.Average(), deltas.Average() / Fix64.Precision); output.WriteLine("Fix64.AdaptiveInvert time = {0}ms, float.AdaptiveInvert time = {1}ms", swf.ElapsedMilliseconds, swd.ElapsedMilliseconds); }
public void AdaptiveInvert() { var maxDelta = 0.001m; var deltas = new List <decimal>(); // Scalability and edge cases foreach (var m in testCases) { Matrix3x3 testCase = m; FloatMatrix3x3 floatMatrix = MathConverter.Convert(testCase); FloatMatrix3x3 expected; FloatMatrix3x3.AdaptiveInvert(ref floatMatrix, out expected); Matrix3x3 actual; Matrix3x3.AdaptiveInvert(ref testCase, out actual); bool success = true; foreach (decimal delta in GetDeltas(expected, actual)) { deltas.Add(delta); success &= delta <= maxDelta; } Assert.True(success, string.Format("Precision: Matrix3x3Invert({0}): Expected {1} Actual {2}", testCase, expected, actual)); } output.WriteLine("Max error: {0} ({1} times precision)", deltas.Max(), deltas.Max() / Fix64.Precision); output.WriteLine("Average precision: {0} ({1} times precision)", deltas.Average(), deltas.Average() / Fix64.Precision); }