-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
53 lines (45 loc) · 1.31 KB
/
main.cpp
File metadata and controls
53 lines (45 loc) · 1.31 KB
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
#include "cached_runner.h"
#include "task.h"
#include <iostream>
#include <sstream>
#include <string>
const bool DEBUG = true;
// 디버그 용 출력 함수
void print(const std::string &message) {
if (DEBUG) {
std::cout << message << std::endl;
}
}
// double 값을 문자열로 변환한다
std::string doubleToString(double value) {
std::ostringstream ss;
ss << value;
return ss.str();
}
int main() {
Cache cache;
CachedRunner runner(cache);
Task task;
TaskSet taskSet("resources/task_set.txt");
int index = 0;
// 태스크를 계속 읽어 수행한다
while (taskSet.getNext(task)) {
print("[TASK #" + std::to_string(index++) + "]");
switch (task.type) {
case MULTIPLY: {
double result = runner.multiply(task.filename);
print("multiply(" + task.filename + ") = " + doubleToString(result));
} break;
case PALINDROME: {
int result = runner.palindrome(task.filename);
print("palindrome(" + task.filename + ") = " + std::to_string(result));
} break;
}
print("\n[CACHE]");
print(cache.toString());
}
print("Hits: " + std::to_string(runner.hits()));
print("Misses: " + std::to_string(runner.misses()));
print("Hit ratio: " + doubleToString((double)runner.hits() /
(runner.hits() + runner.misses())));
}