소스 검색

Add updateMatrixWorld benchmark

Marshall Quander 7 년 전
부모
커밋
03681b7bd6
2개의 변경된 파일49개의 추가작업 그리고 0개의 파일을 삭제
  1. 1 0
      test/benchmark/benchmarks.html
  2. 48 0
      test/benchmark/core/UpdateMatrixWorld.js

+ 1 - 0
test/benchmark/benchmarks.html

@@ -15,6 +15,7 @@
   <script src="core/Vector3Storage.js"></script>
   <script src="core/Vector3Length.js"></script>
   <script src="core/Float32Array.js"></script>
+  <script src="core/UpdateMatrixWorld.js"></script>
 </head>
 <body>
   <header>

+ 48 - 0
test/benchmark/core/UpdateMatrixWorld.js

@@ -0,0 +1,48 @@
+(function() {
+
+  THREE = Bench.THREE;
+
+  var position = new THREE.Vector3(1, 1, 1);
+  var scale = new THREE.Vector3(2, 1, 0.5);
+  var rotation = new THREE.Quaternion();
+  rotation.setFromAxisAngle(new THREE.Vector3(0, 1, 0), Math.PI / 8);
+  var createLocallyOffsetChild = function() {
+    var child = new THREE.Object3D();
+    child.position = position;
+    child.scale = scale;
+    child.rotation = rotation;
+    return child;
+  };
+
+  var generateSceneGraph = function(root, depth, breadth, initObject) {
+    if (depth > 0) {
+      for (var i = 0; i < breadth; i++) {
+        var child = initObject();
+        root.add(child);
+        generateSceneGraph(child, depth - 1, breadth, initObject);
+      }
+    }
+    return root;
+  };
+
+  var nodeCount = function(root) {
+    return root.children.reduce(function(acc, x) { return acc + nodeCount(x); }, 1);
+  };
+
+  var rootA = generateSceneGraph(new THREE.Object3D(), 100, 1, createLocallyOffsetChild);
+  var rootB = generateSceneGraph(new THREE.Object3D(), 3, 10, createLocallyOffsetChild);
+  var rootC = generateSceneGraph(new THREE.Object3D(), 9, 3, createLocallyOffsetChild);
+
+  var s = Bench.newSuite("Update world transforms");
+
+  s.add('Update graph depth=100, breadth=1 (' + nodeCount(rootA) + ' nodes)', function() {
+    rootA.updateMatrixWorld(true);
+  });
+  s.add('Update graph depth=3, breadth=10 (' + nodeCount(rootB) + ' nodes)', function() {
+    rootB.updateMatrixWorld(true);
+  });
+  s.add('Update graph depth=9, breadth=3 (' + nodeCount(rootC) + ' nodes)', function() {
+    rootC.updateMatrixWorld(true);
+  });
+
+})();