Browse Source

vector3 length inline/function call test.

Ben Houston 12 years ago
parent
commit
e17ac5c1ac
2 changed files with 101 additions and 0 deletions
  1. 20 0
      test/benchmark/benchmarking_vector3inline.html
  2. 81 0
      test/benchmark/core/Vector3Inline.js

+ 20 - 0
test/benchmark/benchmarking_vector3inline.html

@@ -0,0 +1,20 @@
+<!DOCTYPE html>
+<html>
+<head>
+  <meta charset="utf-8">
+  <title>ThreeJS Benchmark Tests - Using Files in /src</title>
+</head>
+<body>
+
+  During this Benchmarking test the browser will be unresponsive.<br/><br/>
+
+  Benchmark output is written to the JavaScript console.  To access the JavaScript console presss Ctrl-Shift-J.
+
+  <script src="benchmark-1.0.0.js"></script>
+
+  <!-- add class-based unit tests below -->
+
+  <script src="core/Vector3Inline.js"></script>
+  
+</body>
+</html>

+ 81 - 0
test/benchmark/core/Vector3Inline.js

@@ -0,0 +1,81 @@
+THREE = {};
+    
+THREE.Vector3 = function ( x, y, z ) {
+
+    this.x = x || 0;
+    this.y = y || 0;
+    this.z = z || 0;
+
+};
+
+THREE.Vector3.prototype = {
+
+    constructor: THREE.Vector3,
+    
+    lengthSq: function () {
+
+            return this.x * this.x + this.y * this.y + this.z * this.z;
+
+    },
+
+    length: function () {
+
+            return Math.sqrt( this.lengthSq() );
+
+    },
+
+    length2: function () {
+
+            return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z );
+
+    }
+    
+};
+
+var a = [];
+
+for ( var i = 0; i < 100000; i ++ ) {
+    
+    var x = Math.random(); 
+    var y = Math.random();
+    var z = Math.random();
+    
+    a[ i ] = new THREE.Vector3( x, y, z );
+    
+}
+
+
+var suite = new Benchmark.Suite;
+
+suite.add('InlineCallTest', function() {
+
+    var result = 0;
+
+    for ( var i = 0; i < 100000; i ++ ) {
+
+        result += a[ i ].length2();
+
+    }
+
+});
+
+suite.add('FunctionCallTest', function() {
+    var result = 0;
+
+    for ( var i = 0; i < 100000; i ++ ) {
+
+        result += a[ i ].length();
+
+    }
+});
+
+suite.on('cycle', function(event, bench) {
+  console.log(String(event.target));
+});
+
+suite.on('complete', function() {
+  console.log('Fastest is ' + this.filter('fastest').pluck('name'));
+  console.log( "Done" );
+});
+
+suite.run(true);