-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathCMinerSimulatorTest.cpp
executable file
·54 lines (43 loc) · 1.55 KB
/
CMinerSimulatorTest.cpp
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
//#include <zconf.h>
#include <iostream>
#include <unistd.h>
using std::cout;
using std::endl;
#include "Simulator/CMinerSimulator.h"
#include "Utils/Utils.h"
int main(int argc, char* argv[]) {
// vector<string> logs = Utils::getRandomLogs(1000);
for (int fileCacheSize = 1; fileCacheSize <= 50; fileCacheSize ++) {
CMinerSimulator simulator(fileCacheSize);
// 获取数据集
vector<string> logs = simulator.getDataSet("./audit.log", "/user/root/input/sogou/query-log-");
// 生成关联规则
simulator.setDataSet(logs);
simulator.generateRules();
// 模拟读取数据,利用关联规则提高Cache命中率
int hitCount = 0;
int prefetchCount = 0;
clock_t totalTime = 0;
for (const string ¤tFile : logs) {
clock_t start = clock();
string targetFile = simulator.getFileFromCache(currentFile);
// Miss
if (targetFile.empty()) {
// read miss causes prediction
for (const string &file : simulator.getPredictFiles(currentFile)) {
simulator.putFileIntoCache(file, file);
prefetchCount ++;
}
}
// Hit
else {
hitCount ++;
}
clock_t end = clock();
totalTime += end - start;
}
// 输出命中率
cout << "Cache size: " << fileCacheSize << "\t" << "Hit ratio: " << hitCount * 1.0 / logs.size() << endl;
}
// logs.clear();
}