forked from zcbenz/BPlusTree
-
Notifications
You must be signed in to change notification settings - Fork 0
/
zbpt_benchmark.cc
154 lines (134 loc) · 4.91 KB
/
zbpt_benchmark.cc
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#include <assert.h>
#include <chrono>
#include <cmath>
#include <fstream>
#include <iostream>
#include <ratio>
#include <string>
#include "util/benchmark_utils.h"
#include "zbpt.h"
#define KEY(key, rid) bpt::vec4_t(date2keyarr(key, rid))
#define SIZE 10000
// Provide some namespace shortcuts
using std::cout;
using std::chrono::duration;
using std::chrono::high_resolution_clock;
typedef bpt::bplus_tree_zmap bt;
typedef bpt::vec4_t key;
int test(bt db, u_int8_t key_idx, int range, bpt::value_t* values) {
bool next = true;
int return_num = 0;
const std::vector<uint32_t> all_zero = {0, 0, 0, 0};
bpt::vec4_t next_key(all_zero);
int next_pos;
// key left_key = KEY("1993-12-04|1994-01-07|1994-01-01", 0);
std::queue<tuple<off_t, int>> state_queue;
switch (range) {
case 1: {
// key l_key = KEY("1993-12-04|1994-01-07|1994-01-01", 0);
// // key r_key = KEY("1993-12-05|1994-01-08|1994-01-02", 1);
// while (next) {
// return_num += db.search_single(l_key, values, SIZE, &next,
// key_idx);
// }
// return return_num;
key l_key = KEY("1994-10-16|1994-09-25|1994-10-19", 0);
key r_key = KEY("1994-10-17|1994-09-26|1994-10-20", 100000000);
while (next) {
return_num += db.search_range_single(&l_key, r_key, values, SIZE, &next,
key_idx, &state_queue, &next_pos);
}
return return_num;
}
case 2: {
key l_key = KEY("1993-12-04|1994-01-07|1994-01-01", 0);
key r_key = KEY("1993-12-06|1994-01-09|1994-01-03", 2);
while (next) {
return_num += db.search_range_single(&l_key, r_key, values, SIZE, &next,
key_idx, &state_queue, &next_pos);
}
return return_num;
}
case 4: {
key l_key = KEY("1993-12-04|1994-01-07|1994-01-01", 0);
key r_key = KEY("1993-12-08|1994-01-11|1994-01-05", 4);
while (next) {
return_num += db.search_range_single(&l_key, r_key, values, SIZE, &next,
key_idx, &state_queue, &next_pos);
}
return return_num;
}
case 8: {
key l_key = KEY("1993-12-04|1994-01-07|1994-01-01", 0);
key r_key = KEY("1993-12-12|1994-01-15|1994-01-09", 8);
while (next) {
return_num += db.search_range_single(&l_key, r_key, values, SIZE, &next,
key_idx, &state_queue, &next_pos);
}
return return_num;
}
case 16: {
key l_key = KEY("1993-12-04|1994-01-07|1994-01-01", 0);
key r_key = KEY("1993-12-20|1994-01-23|1994-01-17", 16);
while (next) {
return_num += db.search_range_single(&l_key, r_key, values, SIZE, &next,
key_idx, &state_queue, &next_pos);
}
return return_num;
}
case 30: {
key l_key = KEY("1993-12-04|1994-01-07|1994-01-01", 0);
key r_key = KEY("1994-01-04|1994-02-07|1994-02-01", 30);
while (next) {
return_num += db.search_range_single(&l_key, r_key, values, SIZE, &next,
key_idx, &state_queue, &next_pos);
}
return return_num;
}
case 60: {
// key l_key = KEY("1993-12-04|1994-01-07|1994-01-01", 0);
// key r_key = KEY("1994-02-04|1994-03-07|1994-03-01", 60);
key l_key = KEY("1994-10-16|1994-09-25|1994-10-19", 0);
key r_key = KEY("1994-12-16|1994-11-25|1994-12-19", 60);
while (next) {
return_num += db.search_range_single(&l_key, r_key, values, SIZE, &next,
key_idx, &state_queue, &next_pos);
}
return return_num;
}
default: {
printf("Wrong Parameter!\n");
return 0;
}
}
}
int main(int argc, char** argv) {
high_resolution_clock::time_point start;
high_resolution_clock::time_point end;
duration<double, std::milli> duration_sec;
cout << "Begin load!\n";
bt tree_vec4("zbpt_vec4.db", false);
bpt::value_t* values = new bpt::value_t[SIZE];
cout << "Begin test!\n";
int range[7] = {1, 2, 4, 8, 16, 30, 60};
for (u_int8_t i = 0; i < 3; i++) {
for (int j = 0; j < 7; j++) {
// Get the starting timestamp
start = high_resolution_clock::now();
int num = test(tree_vec4, i, range[j], values);
// Get the ending timestamp
end = high_resolution_clock::now();
// Convert the calculated duration to a double using the standard
// library
duration_sec =
std::chrono::duration_cast<duration<double, std::milli>>(end - start);
// Durations are converted to milliseconds already thanks to
// std::chrono::duration_cast
cout << "key_idx = " << (int)i << " range = " << range[j]
<< " num = " << num << " time = " << duration_sec.count() << "ms"
<< std::endl;
// cout << "Total time: " << duration_sec.count() << "ms\n";
}
}
return 0;
}