-
Notifications
You must be signed in to change notification settings - Fork 4
/
_test.js
77 lines (67 loc) · 1.69 KB
/
_test.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
function geta(x) {
return x & 0xffff;
}
function getb(x) {
return x >> 16;
}
function makec(a, b) {
return a | (b << 16)
}
function testBox() {
var start = Date.now()
map1 = []
map1[0] = 1
for (var i = 0; i < 5000000; ++i) {
k = i % 30000
map1[i] = k * k + map1[Math.floor(i / 2)] + 1;
}
var el = Date.now()-start
console.log('Operations without boxing: ', el);
start = Date.now()
map2 = []
map2[0] = { num: 1, n2:2 }
for (var i = 0; i < 5000000; ++i) {
k = i % 30000
map2[i] = { num: k * k, n2: k+2 + map2[Math.floor(i / 2)].n2 + 1};
}
el = Date.now() - start
console.log('Operations with boxing: ', el);
var start = Date.now()
map4 = []
map4[0] = makec(1, 2)
for (var i = 0; i < 5000000; ++i) {
k = i % 30000
map4[i] = makec(k * k, k + 2 + getb(map4[Math.floor(i / 2)]) + 1);
}
var el = Date.now() - start
console.log('Operations with shifts: ', el);
var start = Date.now()
map5 = new Uint32Array()
map5[0] = makec(1, 2)
for (var i = 0; i < 5000000; ++i) {
k = i % 30000
map5[i] = makec(k * k, k + 2 + getb(map5[Math.floor(i / 2)]) + 1);
}
var el = Date.now() - start
console.log('Operations with shifts in arrays: ', el);
console.log('x')
/*
start = Date.now()
map31 = []
map32 = []
map31[0] = 1
map32[0] = 2
for (var i = 0; i < 5000000; ++i) {
map31[i] = i * i
map32[i] += i+2 + map32[Math.round(i / 2)] + 1;
}
el = Date.now() - start
console.log('Operations with dblmap: ', el);
*/
}
function webGLStart() {
testBox()
testBox()
testBox()
return;
}