forked from mrdoob/three.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVector3Storage.js
More file actions
113 lines (72 loc) · 1.99 KB
/
Vector3Storage.js
File metadata and controls
113 lines (72 loc) · 1.99 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
(function() {
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.elements[0] * this.elements[0] + this.elements[1] * this.elements[1] + this.elements[2] * this.elements[2]);
}
};
THREE.Vector3Y = function(x, y, z) {
this.elements = [x || 0, y || 1, z || 2];
};
THREE.Vector3Y.prototype = {
constructor: THREE.Vector3Y,
length: function() {
return Math.sqrt(this.elements[0] * this.elements[0] + this.elements[1] * this.elements[1] + this.elements[2] * this.elements[2]);
}
};
var suite = Bench.newSuite("Vector 3 Storage");
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.add('Vector3-Array', function() {
var array = [];
for (var i = 0; i < 100000; i++) {
var v = new THREE.Vector3Y(i, i, i);
array.push(v);
}
var result = 0;
for (var i = 0; i < 100000; i++) {
var v = array[i];
result += v.length();
}
});
})();