Pārlūkot izejas kodu

cleaned up benchmark tests so that inputs to each test are consistent per @gero3's suggestion.

Ben Houston 12 gadi atpakaļ
vecāks
revīzija
e964e04591

+ 1 - 1
test/benchmark/benchmarking_float32array_accesspatterns.html → test/benchmark/benchmarking_float32array.html

@@ -30,7 +30,7 @@
 
   <!-- add class-based unit tests below -->
 
-  <script src="core/Float32ArrayAccessPatterns.js"></script>
+  <script src="core/Float32Array.js"></script>
   
 </body>
 </html>

+ 1 - 1
test/benchmark/benchmarking_vector3inline.html → test/benchmark/benchmarking_vector3length.html

@@ -14,7 +14,7 @@
 
   <!-- add class-based unit tests below -->
 
-  <script src="core/Vector3Inline.js"></script>
+  <script src="core/Vector3Length.js"></script>
   
 </body>
 </html>

+ 108 - 0
test/benchmark/core/Float32Array.js

@@ -0,0 +1,108 @@
+
+var input = new Float32Array( 10000 * 3 );
+var output = new Float32Array( 10000 * 3 );
+
+for( var j = 0, jl = input.length; j < jl; j ++ ) {
+	input[j] = j;
+}
+
+var inputVectors = [];
+var outputVectors = [];
+
+for( var j = 0, jl = input.length/3; j < jl; j ++ ) {
+	inputVectors.push( new THREE.Vector3( j*3, j*3+1, j*3+2 ) );
+	outputVectors.push( new THREE.Vector3() );
+}
+
+var suite = new Benchmark.Suite;
+
+suite.add('Float32ArrayFloat32ArrayCopyTest', function() {
+	var value3 = new Float32Array( 3 );
+	for (var i = 0, il = input.length / 3; i < il; i += 3) {
+	  value3[0] = input[i + 0];
+	  value3[1] = input[i + 1];
+	  value3[2] = input[i + 2];
+	  value3[0] *= 1.01;
+	  value3[1] *= 1.03;
+	  value3[2] *= 0.98;
+	  output[i + 0] = value3[0];
+	  output[i + 1] = value3[1];
+	  output[i + 2] = value3[2];
+	}
+});
+
+suite.add('Float32ArrayArrayCopyTest', function() {
+	var value2 = [0,0,0];
+	for (var i = 0, il = input.length / 3; i < il; i += 3) {
+	  value2[0] = input[i + 0];
+	  value2[1] = input[i + 1];
+	  value2[2] = input[i + 2];
+	  value2[0] *= 1.01;
+	  value2[1] *= 1.03;
+	  value2[2] *= 0.98;
+	  output[i + 0] = value2[0];
+	  output[i + 1] = value2[1];
+	  output[i + 2] = value2[2];
+	}
+});
+
+suite.add('Float32CopyArray', function() {
+	var x, y, z;
+	for (var i = 0, il = input.length / 3; i < il; i += 3) {
+	  x = input[i + 0];
+	  y = input[i + 1];
+	  z = input[i + 2];
+	  x *= 1.01;
+	  y *= 1.03;
+	  z *= 0.98;
+	  output[i + 0] = x;
+	  output[i + 1] = y;
+	  output[i + 2] = z;
+	}
+});
+
+suite.add('Float32ArrayVector3CopyTest', function() {
+	var value = new THREE.Vector3();
+	for (var i = 0, il = input.length / 3; i < il; i += 3) {
+	  value.x = input[i + 0];
+	  value.y = input[i + 1];
+	  value.z = input[i + 2];
+	  value.x *= 1.01;
+	  value.y *= 1.03;
+	  value.z *= 0.98;
+	  output[i + 0] = value.x;
+	  output[i + 1] = value.y;
+	  output[i + 2] = value.z;
+	}
+});
+
+suite.add('Vector3ArrayVector3Direct', function() {
+	for (var i = 0, il = inputVectors.length; i < il; i ++ ) {
+		outputVectors[i].copy( inputVectors[i] );
+		outputVectors[i].x *= 1.01;
+		outputVectors[i].y *= 1.03;
+		outputVectors[i].z *= 0.98;
+	}
+});
+
+suite.add('Vector3ArrayVector3Copy', function() {
+	var value = new THREE.Vector3();
+	for (var i = 0, il = inputVectors.length; i < il; i ++ ) {
+	  value.copy( inputVectors[i] );
+	  value.x *= 1.01;
+	  value.y *= 1.03;
+	  value.z *= 0.98;
+	  outputVectors[i].copy( value );
+	}
+});
+
+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);

+ 0 - 155
test/benchmark/core/Float32ArrayAccessPatterns.js

@@ -1,155 +0,0 @@
-
-var array = new Float32Array( 10000 * 3 );
-
-for( var j = 0, jl = array.length; j < jl; j ++ ) {
-	array[j] = j;
-}
-
-var vectorArray = [];
-
-for( var j = 0, jl = array.length/3; j < jl; j ++ ) {
-	vectorArray.push( new THREE.Vector3( j*3, j*3+1, j*3+2 ) );
-}
-
-var Float32ArrayCopyTest = function( array ) {
-	var x, y, z;
-	for (var i = 0, il = array.length / 3; i < il; i += 3) {
-	  x = array[i + 0];
-	  y = array[i + 1];
-	  z = array[i + 2];
-	  x *= 1.01;
-	  y *= 1.03;
-	  z *= 0.98;
-	  array[i + 0] = x;
-	  array[i + 1] = y;
-	  array[i + 2] = z;
-	}
-};
-
-var Float32ArrayDirectTest = function( array ) {
-	for (var i = 0, il = array.length / 3; i < il; i += 3) {
-	  array[i + 0] *= 1.01;
-	  array[i + 1] *= 1.03;
-	  array[i + 2] *= 0.98;
-	}
-};
-
-
-var Float32ArrayVector3CopyTest = function( array ) {
-	var value = new THREE.Vector3();
-	for (var i = 0, il = array.length / 3; i < il; i += 3) {
-	  value.x = array[i + 0];
-	  value.y = array[i + 1];
-	  value.z = array[i + 2];
-	  value.x *= 1.01;
-	  value.y *= 1.03;
-	  value.z *= 0.98;
-	  array[i + 0] = value.x;
-	  array[i + 1] = value.y;
-	  array[i + 2] = value.z;
-	}
-};
-
-var Float32ArrayArrayCopyTest = function( array ) {
-	var value2 = [0,0,0];
-	for (var i = 0, il = array.length / 3; i < il; i += 3) {
-	  value2[0] = array[i + 0];
-	  value2[1] = array[i + 1];
-	  value2[2] = array[i + 2];
-	  value2[0] *= 1.01;
-	  value2[1] *= 1.03;
-	  value2[2] *= 0.98;
-	  array[i + 0] = value2[0];
-	  array[i + 1] = value2[1];
-	  array[i + 2] = value2[2];
-	}
-};
-
-var Float32ArrayFloat32ArrayCopyTest = function( array ) {
-	var value3 = new Float32Array( 3 );
-	for (var i = 0, il = array.length / 3; i < il; i += 3) {
-	  value3[0] = array[i + 0];
-	  value3[1] = array[i + 1];
-	  value3[2] = array[i + 2];
-	  value3[0] *= 1.01;
-	  value3[1] *= 1.03;
-	  value3[2] *= 0.98;
-	  array[i + 0] = value3[0];
-	  array[i + 1] = value3[1];
-	  array[i + 2] = value3[2];
-	}
-};
-
-
-var Vector3ArrayVector3CopyTest = function( array ) {
-	var value = new THREE.Vector3();
-	for (var i = 0, il = vectorArray.length; i < il; i ++ ) {
-	  value.copy( vectorArray[i] );
-	  value.x *= 1.01;
-	  value.y *= 1.03;
-	  value.z *= 0.98;
-	  vectorArray[i].copy( value );
-	}
-};
-
-var Vector3ArrayVector3RefTest = function( array ) {
-	for (var i = 0, il = vectorArray.length; i < il; i ++ ) {
-	  var value = vectorArray[i];
-	  value.x *= 1.01;
-	  value.y *= 1.03;
-	  value.z *= 0.98;
-	}
-};
-
-var Vector3ArrayVector3DirectTest = function( array ) {
-	for (var i = 0, il = vectorArray.length; i < il; i ++ ) {
-	  vectorArray[i].x *= 1.01;
-	  vectorArray[i].y *= 1.03;
-	  vectorArray[i].z *= 0.98;
-	}
-};
-
-var suite = new Benchmark.Suite;
-
-suite.add('Float32ArrayFloat32ArrayCopyTest', function() {
-  Float32ArrayFloat32ArrayCopyTest( array );
-});
-
-suite.add('Float32DirectArray', function() {
-  Float32ArrayDirectTest( array );
-});
-
-suite.add('Float32ArrayArrayCopyTest', function() {
-  Float32ArrayArrayCopyTest( array );
-});
-
-suite.add('Float32CopyArray', function() {
-  Float32ArrayCopyTest( array );
-});
-
-suite.add('Float32ArrayVector3CopyTest', function() {
-  Float32ArrayVector3CopyTest( array );
-});
-
-suite.add('Vector3ArrayVector3Ref', function() {
-  Vector3ArrayVector3RefTest( array );
-});
-
-suite.add('Vector3ArrayVector3Direct', function() {
-  Vector3ArrayVector3DirectTest( array );
-});
-
-suite.add('Vector3ArrayVector3Copy', function() {
-  Vector3ArrayVector3CopyTest( array );
-});
-
-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);

+ 12 - 5
test/benchmark/core/Vector3Inline.js → test/benchmark/core/Vector3Length.js

@@ -36,17 +36,24 @@ 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 );
+    a[ i ] = new THREE.Vector3( i * 0.01, i * 2, i * -1.3 );
     
 }
 
 
 var suite = new Benchmark.Suite;
 
+suite.add('NoCallTest', function() {
+
+    var result = 0;
+
+    for ( var i = 0; i < 100000; i ++ ) {
+        var v = a[i];
+        result += Math.sqrt( v.x * v.x + v.y * v.y + v.z * v.z );
+    }
+
+});
+
 suite.add('InlineCallTest', function() {
 
     var result = 0;