فهرست منبع

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

Ben Houston 12 سال پیش
والد
کامیت
6e03407099
1فایلهای تغییر یافته به همراه34 افزوده شده و 1 حذف شده
  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));
 });