Matrix3x2Benchmarks.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. using System.Runtime.CompilerServices;
  2. using BenchmarkDotNet.Attributes;
  3. using Microsoft.Xna.Framework;
  4. namespace MonoGame.Extended.Benchmarks;
  5. [MemoryDiagnoser]
  6. public class Matrix3x2Benchmarks
  7. {
  8. private Matrix2 _matrix2;
  9. private Matrix3x2 _matrix3x2;
  10. [GlobalSetup]
  11. public void Setup()
  12. {
  13. _matrix2 = new Matrix2(1, 2, 3, 4, 5, 6);
  14. _matrix3x2 = new Matrix3x2(1, 2, 3, 4, 5, 6);
  15. }
  16. [Benchmark]
  17. public Vector2 Matrix2_getTranslation() => _matrix2.Translation;
  18. [Benchmark]
  19. public Vector2 Matrix3x2_getTranslation() => _matrix3x2.Translation;
  20. // [Benchmark]
  21. // public float Matrix2_getRotation() => _matrix2.Rotation;
  22. // [Benchmark]
  23. // public float Matrix3x2_getRotation() => _matrix3x2.Rotation;
  24. // [Benchmark]
  25. // public Vector2 Matrix2_getScale() => _matrix2.Scale;
  26. // [Benchmark]
  27. // public Vector2 Matrix3x2_getScale() => _matrix3x2.Scale;
  28. // [Benchmark]
  29. // public (Vector2, float, Vector2) Matrix2_Decompose()
  30. // {
  31. // Vector2 translation = _matrix2.Translation;
  32. // float rotation = _matrix2.Rotation;
  33. // Vector2 scale = _matrix2.Scale;
  34. // return (translation, rotation, scale);
  35. // }
  36. // [Benchmark]
  37. // public (Vector2, float, Vector2) Matrix3x2_Decompose()
  38. // {
  39. // _matrix3x2.Decompose(out Vector2 translation, out float rotation, out Vector2 scale);
  40. // return (translation, rotation, scale);
  41. // }
  42. // [Benchmark]
  43. // public Vector2 Matrix2_Transform() => _matrix2.Transform(Vector2.One);
  44. // [Benchmark]
  45. // public Vector2 Matrix3x2_Transform() => _matrix3x2.Transform(Vector2.One);
  46. // [Benchmark]
  47. // public float Matrix2_Determinant() => _matrix2.Determinant();
  48. // [Benchmark]
  49. // public float Matrix3x2_Determinant() => _matrix3x2.Determinant();
  50. // [Benchmark]
  51. // public Matrix2 Matrix2_CreateFrom()
  52. // {
  53. // Matrix2.CreateFrom(Vector2.Zero, 1.0f, Vector2.One, Vector2.Zero, out Matrix2 result);
  54. // return result;
  55. // }
  56. // [Benchmark]
  57. // public Matrix3x2 Matrix3x2_CreateFrom()
  58. // {
  59. // Matrix3x2.CreateFrom(Vector2.Zero, 1.0f, Vector2.One, Vector2.Zero, out Matrix3x2 result);
  60. // return result;
  61. // }
  62. // [Benchmark]
  63. // public Matrix2 Matrix2_CreateRotationZ()
  64. // {
  65. // Matrix2.CreateRotationZ(1.0f, out Matrix2 result);
  66. // return result;
  67. // }
  68. // [Benchmark]
  69. // public Matrix3x2 Matrix3x2_CreateRotationZ()
  70. // {
  71. // Matrix3x2.CreateRotationZ(1.0f, out Matrix3x2 result);
  72. // return result;
  73. // }
  74. // [Benchmark]
  75. // public Matrix2 Matrix2_CreateScale()
  76. // {
  77. // Matrix2.CreateScale(1.0f, out Matrix2 result);
  78. // return result;
  79. // }
  80. // [Benchmark]
  81. // public Matrix3x2 Matrix3x2_CreateScale()
  82. // {
  83. // Matrix3x2.CreateScale(1.0f, out Matrix3x2 result);
  84. // return result;
  85. // }
  86. // [Benchmark]
  87. // public Matrix2 Matrix2_CreateTranslation()
  88. // {
  89. // Matrix2.CreateTranslation(1.0f, 1.0f, out Matrix2 result);
  90. // return result;
  91. // }
  92. // [Benchmark]
  93. // public Matrix3x2 Matrix3x2_CreateTranslation()
  94. // {
  95. // Matrix3x2.CreateTranslation(1.0f, 1.0f, out Matrix3x2 result);
  96. // return result;
  97. // }
  98. // [Benchmark]
  99. // public Matrix2 Matrix2_Invert()
  100. // {
  101. // Matrix2.Invert(ref _matrix2, out Matrix2 result);
  102. // return result;
  103. // }
  104. // [Benchmark]
  105. // public Matrix3x2 Matrix3x2_Invert()
  106. // {
  107. // Matrix3x2.Invert(_matrix3x2);
  108. // return _matrix3x2;
  109. // }
  110. // [Benchmark]
  111. // public Matrix2 Matrix2_Add()
  112. // {
  113. // return Matrix2.Add(_matrix2, _matrix2);
  114. // }
  115. // [Benchmark]
  116. // public Matrix3x2 Matrix3x2_Add()
  117. // {
  118. // return Matrix3x2.Add(_matrix3x2, _matrix3x2);
  119. // }
  120. // [Benchmark]
  121. // public Matrix2 Matrix2_Subtract()
  122. // {
  123. // return Matrix2.Subtract(_matrix2, _matrix2);
  124. // }
  125. // [Benchmark]
  126. // public Matrix3x2 Matrix3x2_Subtract()
  127. // {
  128. // return Matrix3x2.Subtract(_matrix3x2, _matrix3x2);
  129. // }
  130. // [Benchmark]
  131. // public Matrix2 Matrix2_Multiply()
  132. // {
  133. // return Matrix2.Subtract(_matrix2, _matrix2);
  134. // }
  135. // [Benchmark]
  136. // public Matrix3x2 Matrix3x2_Multiply()
  137. // {
  138. // return Matrix3x2.Multiply(_matrix3x2, _matrix3x2);
  139. // }
  140. // [Benchmark]
  141. // public Matrix2 Matrix2_Divide()
  142. // {
  143. // return Matrix2.Divide(_matrix2, _matrix2);
  144. // }
  145. // [Benchmark]
  146. // public Matrix3x2 Matrix3x2_Divide()
  147. // {
  148. // return Matrix3x2.Divide(_matrix3x2, _matrix3x2);
  149. // }
  150. // [Benchmark]
  151. // public Matrix Matrix2_ToMatrix()
  152. // {
  153. // return _matrix2.ToMatrix();
  154. // }
  155. // [Benchmark]
  156. // public Matrix Matrix3x2_ToMatrix()
  157. // {
  158. // return _matrix3x2.ToMatrix();
  159. // }
  160. }