Doodle3D-Slicer/three.js-master/test/benchmark/core/Float32Array.js
2015-06-12 15:58:26 +02:00

108 lines
2.5 KiB
JavaScript
Executable File

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('Float32Array-Float32Array', 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('Float32Array-Array', 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('Float32Array-Literal', 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('Float32Array-Vector3', 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('Vector3Array-Direct', 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('Vector3Array-Vector3', 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);