forked from cedricpinson/osgjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainPerformance.js
86 lines (72 loc) · 2.94 KB
/
mainPerformance.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import QUnit from 'qunit';
import mockup from 'tests/mockup/ockup';
import reportStats from 'benchmarks/reportStats';
import Timer from 'osg/Timer';
import BasicAnimationManager from 'osgAnimation/BasicAnimationManager';
export default function() {
QUnit.module('osg Animation Loop');
QUnit.test('BasicAnimationManager Performance', function() {
var basicAnimationManager = new BasicAnimationManager();
var animations = [];
// create an animation with an animation UpdateCallback in a node
var createAnimation = function() {
var index = animations.length.toString();
var targetName = 'testUpdateMatrixTransform_' + index;
var animation = mockup.createAnimation(
'AnimationTest_' + index,
targetName,
targetName
);
animations.push(animation);
};
var maxAnimations = 50;
for (var i = 0; i < maxAnimations; i++) {
createAnimation();
}
var cbMap = mockup.createAnimationUpdateCallback(animations);
basicAnimationManager.init(animations);
basicAnimationManager._animationsUpdateCallback = cbMap;
basicAnimationManager._registerTargetFoundInAnimationCallback();
basicAnimationManager._registerAnimations();
// console.log( 'nb animations ' + Object.keys( basicAnimationManager._animationsUpdateCallback ).length );
//
var time = 0.0;
var nv = {
getFrameStamp: function() {
return {
getSimulationTime: function() {
return time;
}
};
}
};
var animationMap = basicAnimationManager.getAnimations();
for (var j = 0; j < maxAnimations; j++) {
var animationName = Object.keys(animationMap)[j];
basicAnimationManager.playAnimation(animationName);
}
// add a simple operation to be sure the jit will not discard our code
var fakeResult = 0.0;
var timed = Timer.instance().tick();
console.profile();
console.time('time');
var nCount = 200;
for (var n = 0; n < nCount; n++)
for (var t = 0.0; t < 5.0; t += 0.016) {
time = t;
basicAnimationManager.update(null, nv);
for (
var k = 0, l = basicAnimationManager._animationsUpdateCallbackArray.length;
k < l;
k++
)
fakeResult +=
basicAnimationManager._animationsUpdateCallbackArray[k]._matrix[0];
}
console.timeEnd('time');
console.profileEnd();
timed = Timer.instance().tick() - timed;
module.fakeResult = fakeResult; // keep the variable on a scope to avoid JIT otimimization and remove code
reportStats(timed, 'Animation Loop');
});
}