-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbenchmark.js
64 lines (59 loc) · 1.07 KB
/
benchmark.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
var L = require('./');
var list = L.init();
var arr = [];
var hash = {};
var length = 100000;
for (i = 0; i != length; i++) {
arr.push({data:i});
}
console.time('arr');
for (var i = 0, l = length; i < l; i++) {
if (arr[i].data % 2) {
arr.splice(i, 1);
l--;
i--;
}
}
console.timeEnd('arr');
console.log(arr.length);
var arr = [];
for (var i = 0; i != length; i++) {
arr.push({data:i});
}
console.time('arr2');
var res = [];
for (var i = 0; i !=length; i++) {
if (!(arr[i].data % 2)) {
res.push(arr[i]);
}
}
console.timeEnd('arr2');
console.log(res.length);
for (i=0; i != length; i++) {
L.appendBefore(list, {data:i});
}
console.time('list');
L.traversal(list, function(item) {
if (item.data % 2) {
L.remove(item);
}
})
console.timeEnd('list');
var i = 0;
L.traversal(list, function(item) {
i++;
});
console.log(i);
for (var i = 0; i != length; i++) {
hash[i] = {
data: i
};
}
console.time('hash');
for (var key in hash) {
if (hash[key].data % 2) {
delete hash[key];
}
}
console.timeEnd('hash');
console.log(Object.keys(hash).length);