-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
50 lines (47 loc) · 1 KB
/
main.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
#include <iostream>
#include "bmgr.h"
#include "instruction.h"
#include <ctime>
#include <log.h>
using namespace std;
/**
* 初始化数据库文件
* 随机写入50000个page
*/
void init_db()
{
auto bm = make_shared<BMgr>();
for (unsigned int j = 1; j <= 50000; j++)
{
auto frame = generate_frame();
bm->fix_new_page(frame);
}
}
/**
* 执行test
* @param bm BMgr的shared_ptr
*/
void run_test(const BMgr::sptr &bm)
{
auto ins_vector = Instruction::read_instructions("../data-5w-50w-zipf.txt");
int index = 0;
for (auto &i : *ins_vector)
{
index++;
i.execute(bm);
}
}
int main()
{
init_db();
auto bm = make_shared<BMgr>();
clock_t start, end;
start = clock();
run_test(bm);
end = clock();
char log[500];
sprintf(log, "buffer_size:%d,total_io:%d,total_hit:%d,interval:%0.2fs",
BUFFER_SIZE, bm->get_io_count(), bm->get_hit_count(), (float)(end - start) / CLOCKS_PER_SEC);
logger(log);
return 0;
}