vec_perf.html 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <!DOCTYPE html>
  2. <html>
  3. <!--
  4. Copyright The Closure Library Authors. All Rights Reserved.
  5. Use of this source code is governed by the Apache License, Version 2.0.
  6. See the COPYING file for details.
  7. -->
  8. <head>
  9. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  10. <title>Closure Performance Tests - Vector math</title>
  11. <link rel="stylesheet" type="text/css"
  12. href="../testing/performancetable.css"/>
  13. <script src="../base.js"></script>
  14. <script>
  15. goog.require('goog.crypt');
  16. goog.require('goog.string');
  17. goog.require('goog.testing.PerformanceTable');
  18. goog.require('goog.testing.jsunit');
  19. goog.require('goog.vec.Vec4');
  20. </script>
  21. </head>
  22. <body>
  23. <h1>Closure Performance Tests - Vector Math</h1>
  24. <p>
  25. <strong>User-agent:</strong>
  26. <script>document.write(navigator.userAgent);</script>
  27. </p>
  28. <div id="perfTable"></div>
  29. <hr>
  30. <script>
  31. var table = new goog.testing.PerformanceTable(
  32. goog.dom.getElement('perfTable'));
  33. var createVec4FromValues = goog.vec.Vec4.createFromValues;
  34. var scaleVec4 = goog.vec.Vec4.scale;
  35. var negateVec4ByScaling = function(v, result) {
  36. return scaleVec4(v, -1, result);
  37. };
  38. var negateVec4ByNegation = function(v, result) {
  39. result[0] = -v[0];
  40. result[1] = -v[1];
  41. result[2] = -v[2];
  42. result[3] = -v[3];
  43. return result;
  44. };
  45. var negateVec4ByMultiplication = function(v, result) {
  46. result[0] = -1 * v[0];
  47. result[1] = -1 * v[1];
  48. result[2] = -1 * v[2];
  49. result[3] = -1 * v[3];
  50. return result;
  51. };
  52. function createRandomVec4() {
  53. return createVec4FromValues(
  54. Math.random(),
  55. Math.random(),
  56. Math.random(),
  57. Math.random());
  58. }
  59. function testNegateVec4ByScaling() {
  60. var v = createRandomVec4();
  61. for (var i = 0; i < 2000000; i++) {
  62. // Warm the trace tree to see if that makes a difference.
  63. scaleVec4(v, 1, v);
  64. }
  65. table.run(
  66. function() {
  67. for (var i = 0; i < 2000000; i++) {
  68. negateVec4ByScaling(v, v);
  69. }
  70. },
  71. 'Negate vector by calling scale()');
  72. }
  73. function testNegateVec4ByNegation() {
  74. var v = createRandomVec4();
  75. for (var i = 0; i < 2000000; i++) {
  76. // Warm the trace tree to see if that makes a difference.
  77. scaleVec4(v, 1, v);
  78. }
  79. table.run(
  80. function() {
  81. for (var i = 0; i < 2000000; i++) {
  82. negateVec4ByNegation(v, v);
  83. }
  84. },
  85. 'Negate vector by negating directly');
  86. }
  87. </script>
  88. </body>
  89. </html>