From 6e03407099b62787fdbe20837decebf616992ef2 Mon Sep 17 00:00:00 2001 From: Ben Houston Date: Fri, 21 Dec 2012 13:33:08 -0500 Subject: [PATCH] add Array storage as another alternative to the Vector3 storage benchmark. fix bug in Float32Array length method. --- test/benchmark/core/Vector3Storage.js | 35 ++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/test/benchmark/core/Vector3Storage.js b/test/benchmark/core/Vector3Storage.js index 1b25764fa2..17aeba93ea 100644 --- a/test/benchmark/core/Vector3Storage.js +++ b/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)); }); -- GitLab