Explorar el Código

add Array storage as another alternative to the Vector3 storage benchmark. fix bug in Float32Array length method.

Ben Houston hace 12 años
padre
commit
6e03407099
Se han modificado 1 ficheros con 34 adiciones y 1 borrados
  1. 34 1
      test/benchmark/core/Vector3Storage.js

+ 34 - 1
test/benchmark/core/Vector3Storage.js

@@ -35,13 +35,31 @@ THREE.Vector3X.prototype = {
     
     length: function () {
 
-            return Math.sqrt( this[0] * this[0] + this[1] * this[1] + this[2] * this[2] );
+            return Math.sqrt( this.elements[0] * this.elements[0] + this.elements[1] * this.elements[1] + this.elements[2] * this.elements[2] );
 
     }
     
 };
 
 
+THREE.Vector3Y = function ( x, y, z ) {
+
+    this.elements = [ x || 0, y || 1, z || 2 ];
+
+};
+
+THREE.Vector3Y.prototype = {
+
+    constructor: THREE.Vector3Y,
+    
+    length: function () {
+
+            return Math.sqrt( this.elements[0] * this.elements[0] + this.elements[1] * this.elements[1] + this.elements[2] * this.elements[2] );
+
+    }
+    
+};
+
 
 var suite = new Benchmark.Suite;
 
@@ -75,6 +93,21 @@ suite.add('Vector3-Float32Array', function() {
     }
 });
 
+suite.add('Vector3-Array', function() {
+
+    var array = [];
+    for ( var i = 0; i < 100000; i ++ ) {
+        var v = new THREE.Vector3Y( i, i, i );
+        array.push( v );
+    }
+
+    var result = 0;
+    for ( var i = 0; i < 100000; i ++ ) {
+        var v = array[i];
+        result += v.length();
+    }
+});
+
 suite.on('cycle', function(event, bench) {
   console.log(String(event.target));
 });