소스 검색

Vector3 storage type benchmark comparison.

Ben Houston 12 년 전
부모
커밋
d52445c25f
2개의 변경된 파일107개의 추가작업 그리고 0개의 파일을 삭제
  1. 20 0
      test/benchmark/benchmarking_vector3storage.html
  2. 87 0
      test/benchmark/core/Vector3Storage.js

+ 20 - 0
test/benchmark/benchmarking_vector3storage.html

@@ -0,0 +1,20 @@
+<!DOCTYPE html>
+<html>
+<head>
+  <meta charset="utf-8">
+  <title>ThreeJS Benchmark Tests - Using Files in /src</title>
+</head>
+<body>
+
+  During this Benchmarking test the browser will be unresponsive.<br/><br/>
+
+  Benchmark output is written to the JavaScript console.  To access the JavaScript console presss Ctrl-Shift-J.
+
+  <script src="benchmark-1.0.0.js"></script>
+
+  <!-- add class-based unit tests below -->
+
+  <script src="core/Vector3Storage.js"></script>
+  
+</body>
+</html>

+ 87 - 0
test/benchmark/core/Vector3Storage.js

@@ -0,0 +1,87 @@
+THREE = {};
+    
+THREE.Vector3 = function ( x, y, z ) {
+
+    this.x = x || 0;
+    this.y = y || 0;
+    this.z = z || 0;
+
+};
+
+THREE.Vector3.prototype = {
+
+    constructor: THREE.Vector3,
+    
+    length: function () {
+
+            return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z );
+
+    }
+    
+};
+
+THREE.Vector3X = function ( x, y, z ) {
+
+    var elements = this.elements = new Float32Array( 3 );
+    elements[0] = x || 0;
+    elements[1] = y || 1;
+    elements[2] = z || 2;
+
+};
+
+THREE.Vector3X.prototype = {
+
+    constructor: THREE.Vector3X,
+    
+    length: function () {
+
+            return Math.sqrt( this[0] * this[0] + this[1] * this[1] + this[2] * this[2] );
+
+    }
+    
+};
+
+
+
+var suite = new Benchmark.Suite;
+
+suite.add('Vector3-Set', function() {
+
+    var array = [];
+    for ( var i = 0; i < 100000; i ++ ) {
+        var v = new THREE.Vector3( i, i, i );
+        array.push( v );
+    }
+
+    var result = 0;
+    for ( var i = 0; i < 100000; i ++ ) {
+        var v = array[i];
+        result += v.length();
+    }
+});
+
+suite.add('Vector3-Float32Array', function() {
+
+    var array = [];
+    for ( var i = 0; i < 100000; i ++ ) {
+        var v = new THREE.Vector3X( 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));
+});
+
+suite.on('complete', function() {
+  console.log('Fastest is ' + this.filter('fastest').pluck('name'));
+  console.log( "Done" );
+});
+
+suite.run(true);