-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
58 lines (49 loc) · 1.04 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
const sizeof = require('object-sizeof');
const BitMap = require('./index');
let bitmap = new BitMap();
let set = new Set();
let arr = [];
function init() {
bitmap = new BitMap();
set = new Set();
arr = [];
}
function test(len) {
init();
console.log('\n');
console.log('test len: ---------------------', len);
for (let i = 0; i < len;) {
bitmap.push(i);
set.add(i);
arr.push(i);
i += Math.floor(Math.random() * 5 + 5);
}
console.log('bitmap size : ', sizeof(bitmap));
console.log('set size : ', sizeof(set));
console.log('arr size : ', sizeof(arr));
console.time('bitmap');
for (let i = 0; i < len; i++) {
if (bitmap.isExist(i)) {
}
}
console.timeEnd('bitmap');
console.time('set');
for (let i = 0; i < len; i++) {
if (set.has(i)) {
}
}
console.timeEnd('set');
console.time('arr');
if (len < 1000000) {
for (let i = 0; i < len; i++) {
if (~arr.indexOf(i)) {
}
}
}
console.timeEnd('arr');
}
test(1000);
test(10000);
test(100000);
test(1000000);
test(5000000);