-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
51 lines (42 loc) · 1.24 KB
/
index.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 { run1wTimes, genGuid } = require("../utils");
const dataToCache = [];
for (let i = 0; i < 1000; i++) {
dataToCache.push({
id: genGuid(),
value: "balabala"
});
}
const again = () => {
const objCache = {};
const setCache = new Set();
let temp;
run1wTimes("cache by Object - add item", () => {
for (let i = 0; i < dataToCache.length; i++) {
const data = dataToCache[i];
objCache[data.id] = data;
}
});
run1wTimes("cache by Set - add item", () => {
for (let i = 0; i < dataToCache.length; i++) {
const data = dataToCache[i];
setCache.add(data);
}
});
// run1wTimes("cache by Object - values", () => {
// temp = Object.keys(objCache).map(key => objCache[key]);
// });
// run1wTimes("cache by Set - values", () => {
// temp = setCache.values();
// });
// run1wTimes("cache by Object - delete item", () => {
// const index = Math.floor(Math.random() * dataToCache.length);
// const data = dataToCache[index];
// delete objCache[data.id];
// });
// run1wTimes("cache by Set - delete item", () => {
// const index = Math.floor(Math.random() * dataToCache.length);
// const data = dataToCache[index];
// setCache.delete(data);
// });
};
again();