提交 6e034070 编写于 作者: B Ben Houston

add Array storage as another alternative to the Vector3 storage benchmark. ...

add Array storage as another alternative to the Vector3 storage benchmark.  fix bug in Float32Array length method.
上级 d52445c2
...@@ -35,13 +35,31 @@ THREE.Vector3X.prototype = { ...@@ -35,13 +35,31 @@ THREE.Vector3X.prototype = {
length: function () { 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; var suite = new Benchmark.Suite;
...@@ -75,6 +93,21 @@ suite.add('Vector3-Float32Array', function() { ...@@ -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) { suite.on('cycle', function(event, bench) {
console.log(String(event.target)); console.log(String(event.target));
}); });
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册