-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathperf-test.js
51 lines (37 loc) · 1.03 KB
/
perf-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
const v8 = require("v8"),
BitArray = require("./bits");
let compare = {
standard: () => {
const arr = [];
for (let x = 0; x < 1e7; x++) {
arr[x] = !!Math.round(Math.random());
}
return arr;
},
fixedArray: () => {
const arr = new Array(1e7);
for (let x = 0; x < 1e7; x++) {
arr[x] = !!Math.round(Math.random());
}
return arr;
},
Uint8Array: () => {
const arr = new Uint8Array(1e7);
for (let x = 0; x < 1e7; x++) {
arr[x] = !!Math.round(Math.random());
}
return arr;
},
bitArray: () => {
const arr = new BitArray({ binSize: 1000 });
for (let x = 0; x < 1e7; x++) {
arr.set(x, !!Math.round(Math.random()));
}
return arr;
}
};
const TEST = "bitArray";
const s1 = v8.getHeapStatistics(),
d = new Date();
let arr = compare[TEST]();
console.log(new Date() - d, v8.getHeapStatistics().total_heap_size - s1.total_heap_size);