-
Notifications
You must be signed in to change notification settings - Fork 33
/
Manage.js
77 lines (60 loc) · 1.54 KB
/
Manage.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
var Cache = require("./Cache");
var Cache_LRU = null, Cache_LFU = null, Cache_FIN;
var round = 100 * 100 * 3;
var Manage = {
"lru": {
cache: Cache.createCache("LRU", 100 * 100 * 5),
suc: 0,
total: 0
},
"lfu": {
cache: Cache.createCache("LFU", 100 * 100 * 5),
suc: 0,
total: 0
}
}
exports.get = function (key) {
if (!round) {
return Cache_FIN.get(key);
}
var value = null;
for (var name in Manage) {
Manage[name].total++;
value = Manage[name].cache.get(key);
if (value) {
Manage[name].suc++;
}
}
// 如果测试完毕,算出命中率
round--;
console.log("Round------>", round);
if (!round) {
var hitRate = {};
var max = {
key: "",
rate: 0
};
for (var key in Manage) {
hitRate[key] = Manage[key].suc / parseFloat(Manage[key].total);
// 找到最高命中率
if (hitRate[key] > max["rate"]) {
max.key = key;
max.rate = hitRate[key];
}
console.log("HIT RATE------>", key, hitRate[key]);
}
console.log("Final Cache------>", max.key);
Cache_FIN = Manage[max.key].cache;
}
return value;
}
exports.set = function (key, value, expire) {
if (!round) {
return Cache_FIN.set(key, value, expire);
}
for (var name in Manage) {
Manage[name].cache.set(key, value, expire);
}
}
exports.create = function () {
}