vec_perf.html 2.6 KB

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