-
Notifications
You must be signed in to change notification settings - Fork 0
/
benchmark_RS.cpp
442 lines (391 loc) · 15.4 KB
/
benchmark_RS.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
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <sstream>
#include "util.h"
#include "./searches/branching_binary_search.h"
#include "./searches/standard_binary_search.h"
#include "./searches/standard_binary_search_no_prefetch.h"
#include "./searches/branchless_binary_search.h"
#include "./searches/branchless_binary_search_no_prefetch.h"
#include "./searches/eytzinger_layout_search.h"
#include "./searches/eytzinger_layout_search_no_prefetch.h"
#include "./searches/kbbs.h"
#include "./searches/kbfs.h"
#include "competitors/rs/include/rs/builder.h"
using namespace std;
int main(int argc, char* argv[]){
char *dataName, *outputPath, *path, *method, *type, *nKary;
int align, shuffle, sort;
std::cout << "Check Parameters..." << std::endl;
//Print help
if(util::cmdOptionExists(argv, argv+argc, "-h"))
{
std::cout << "Help"<< std::endl;
return 0;
}
//Check Input Path parameter
if(!util::cmdOptionExists(argv, argv+argc, "-p"))
{
path = NULL;
}else{
path = util::getCmdOption(argv, argv + argc, "-p");
if(!path || !strncmp ( path, "-", 1 )){
path = NULL;
}
}
//Check Dataset name parameter
if(!util::cmdOptionExists(argv, argv+argc, "-d"))
{
std::cerr << "Dataset name missed...Aborting..." << std::endl;
return 1;
}else{
dataName = util::getCmdOption(argv, argv + argc, "-d");
if(!dataName || !strncmp ( dataName, "-", 1 )){
std::cerr << "Dataset name missed...Aborting..." << std::endl;
return 1;
}
}
//Check Output path and filename parameter
if(!util::cmdOptionExists(argv, argv+argc, "-o"))
{
std::cerr << "Output filename missed...Aborting..." << std::endl;
return 1;
}else{
outputPath = util::getCmdOption(argv, argv + argc, "-o");
if(!outputPath || !strncmp ( outputPath, "-", 1 )){
std::cerr << "Output file path missed...Aborting..." << std::endl;
return 1;
}
}
//Check Method Name parameter
if(!util::cmdOptionExists(argv, argv+argc, "-m"))
{
std::cerr << "Method Name Missed...Aborting..." << std::endl;
return 1;
}else{
method = util::getCmdOption(argv, argv + argc, "-m");
if(!method || !strncmp ( method, "-", 1 )){
std::cerr << "Method name Missed...Aborting..." << std::endl;
return 1;
}
if(strcmp(method, "bbs") && strcmp(method, "bfs") && strcmp(method, "bbsp") && strcmp(method, "bfsp") &&
strcmp(method, "bfe") && strcmp(method, "bfep") && strcmp(method, "lower_bound") &&
strcmp(method, "kbbs") && strcmp(method, "kbfs")){
std::cerr << "Method name Invalid...Aborting..." << std::endl;
return 1;
}
}
//Integer Type parameter
// if(!util::cmdOptionExists(argv, argv+argc, "-t"))
// {
// std::cerr << "Integer Type Missed...Aborting..." << std::endl;
// return 1;
// }else{
// type = util::getCmdOption(argv, argv + argc, "-t");
// if(!type || !strncmp ( type, "-", 1 )){
// std::cerr << "Integer Type Missed...Aborting..." << std::endl;
// return 1;
// }
// // cout << type << endl;
// // cout << strcmp(type, "uint64");
// // cout << strcmp(type, "uint32");
// if(strcmp(type, "uint64") && strcmp(type, "uint32")){
// std::cerr << "Integer Type Invalid...Aborting..." << std::endl;
// return 1;
// }
// }
//Exponent parameter
if(util::cmdOptionExists(argv, argv+argc, "-k")){
nKary = util::getCmdOption(argv, argv + argc, "-k");
}else{
nKary = NULL;
}
// //Check align memory params
// if(!util::cmdOptionExists(argv, argv+argc, "-a"))
// {
// align=0;
// }else{
// align=1;
// }
//
// //Check shuffle data params
// if(!util::cmdOptionExists(argv, argv+argc, "-sh"))
// {
// shuffle=0;
// }else{
// shuffle=1;
// }
//
// //Check sorting data params
// if(!util::cmdOptionExists(argv, argv+argc, "-so"))
// {
// sort=0;
// }else{
// sort=1;
// }
/*
*
* Creating Filename from params
*
*/
std::stringstream ss;
std::string wFn, bFn, oFn, QFn, AFn, BFn;
std::string dataset;
int k=3;
ss.str("");
ss.clear();
if(path == NULL){
ss << dataName << "_uint64_equality_lookups_1M_single";
QFn = ss.str();
ss.str("");
ss.clear();
}else{
ss << path << "Query/" << dataName << "_uint64_equality_lookups_2M_single";
QFn = ss.str();
ss.str("");
ss.clear();
}
if(path == NULL){
ss << dataName << "_uint64";
AFn = ss.str();
ss.str("");
ss.clear();
}else{
ss << path << dataName << "_uint64";
AFn = ss.str();
ss.str("");
ss.clear();
}
ss << outputPath << dataName << ".std.out" <<".csv";
oFn = ss.str();
ss.str("");
ss.clear();
if(nKary != NULL){
k = stoi(nKary);
}
ss << dataName;
dataset = ss.str();
ss.str("");
ss.clear();
std::vector<uint64_t> A = util::load_data<uint64_t>(AFn);
std::vector<uint64_t> Q = util::load_data<uint64_t>(QFn);
std::vector<Row<uint64_t>> data;
data = util::add_values<uint64_t>(A);
// for (uint64_t pos = 0; pos < A.size(); pos++) {
// index_data_.push_back((Row<uint64_t>){A[pos], pos});
// }
// for (uint64_t pos = 0; pos < A.size(); pos++) {
// std::cout << data[pos].key << " -> " << data[pos].data[0] << std::endl;
// }
double timer = 0;
double buildTimer = 0;
std::string searchName;
int64_t ns;
rs::RadixSpline<uint64_t> rs;
uint64_t min = A.front();
uint64_t max = A.back();
if(!strcmp(method, "lower_bound")){
// const auto start = std::chrono::high_resolution_clock::now();
ns = util::timing([&]{
for (uint64_t pos = 0; pos < Q.size(); pos++) {
BranchingBinarySearch<uint64_t>::search(data, Q[pos], 0, A.size()-1);
}
});
// const auto end = std::chrono::high_resolution_clock::now();
// timer = std::chrono::duration_cast<std::chrono::nanoseconds>(end - start).count();
std::cout << ns << " " << Q.size() << std::endl;
std::cout << "Lower_Bound TIME: " << (double)ns/(double)Q.size() << std::endl;
searchName = "LowerBoundSearch";
}else if(!strcmp(method, "bbs")){
if(dataset == "L1_osm_cellids_200M" || dataset == "L2_osm_cellids_200M" || dataset == "L3_osm_cellids_200M"){
rs::Builder<uint64_t>rsb(min,max, 13, 325);
for (const auto& key : A) rsb.AddKey(key);
rs = rsb.Finalize();
}else if(dataset == "L4_osm_cellids_200M"){
rs::Builder<uint64_t>rsb(min,max, 13, 325);
for (const auto& key : A) rsb.AddKey(key);
rs = rsb.Finalize();
}else{
rs::Builder<uint64_t>rsb(min,max);
for (const auto& key : A) rsb.AddKey(key);
rs = rsb.Finalize();
}
ns = util::timing([&]{
rs::SearchBound bound;
uint64_t res = 0;
for (uint64_t pos = 0; pos < Q.size(); pos++) {
if(Q[pos] > A[A.size()-1]){
res = A.size()-1;
}else if(Q[pos] < A[0]){
res = 0;
}else{
bound = rs.GetSearchBound(Q[pos]);
StandardBinarySearchNoPrefetch<uint64_t>::search(data, Q[pos], 0, A.size()-1);
}
}
});
// // const auto start = std::chrono::high_resolution_clock::now();
// // for (uint64_t pos = 0; pos < Q.size(); pos++) {
// // StandardBinarySearchNoPrefetch<uint64_t>::search(data, Q[pos], 0, A.size()-1);
// // }
// // const auto end = std::chrono::high_resolution_clock::now();
// std::cout << "Start: " << start.time_since_epoch().count() << std::endl;
// std::cout << "End: " << end.time_since_epoch().count() << std::endl;
// timer = std::chrono::duration_cast<std::chrono::nanoseconds>(end - start).count();
std::cout << "BBS TIME: " << (double)ns/(double)Q.size() << std::endl;
searchName = "StandardBinarySearchNoPrefetch";
}else if(!strcmp(method, "bbsp")){
// const auto start = std::chrono::high_resolution_clock::now();
ns = util::timing([&]{
for (uint64_t pos = 0; pos < Q.size(); pos++) {
StandardBinarySearch<uint64_t>::search(data, Q[pos], 0, A.size()-1);
}
});
// const auto end = std::chrono::high_resolution_clock::now();
// timer = std::chrono::duration_cast<std::chrono::nanoseconds>(end - start).count();
std::cout << "BBS With Prefetch TIME: " << (double)timer/(double)Q.size() << std::endl;
searchName = "StandardBinarySearch";
}else if(!strcmp(method, "bfs")){
if(dataset == "L1_osm_cellids_200M" || dataset == "L2_osm_cellids_200M" || dataset == "L3_osm_cellids_200M"){
rs::Builder<uint64_t>rsb(min,max, 13, 325);
for (const auto& key : A) rsb.AddKey(key);
rs = rsb.Finalize();
}else if(dataset == "L4_osm_cellids_200M"){
rs::Builder<uint64_t>rsb(min,max, 13, 325);
for (const auto& key : A) rsb.AddKey(key);
rs = rsb.Finalize();
}else{
rs::Builder<uint64_t>rsb(min,max);
for (const auto& key : A) rsb.AddKey(key);
rs = rsb.Finalize();
}
// const auto start = std::chrono::high_resolution_clock::now();
ns = util::timing([&]{
rs::SearchBound bound;
uint64_t res = 0;
for (uint64_t pos = 0; pos < Q.size(); pos++) {
if(Q[pos] > A[A.size()-1]){
res = A.size()-1;
}else if(Q[pos] < A[0]){
res = 0;
}else{
bound = rs.GetSearchBound(Q[pos]);
BranchlessBinarySearchNoPrefetch<uint64_t>::search(data, Q[pos], 0, A.size()-1);
}
}
});
// const auto end = std::chrono::high_resolution_clock::now();
// timer = std::chrono::duration_cast<std::chrono::nanoseconds>(end - start).count();
std::cout << "BFS TIME: " << (double)ns/(double)Q.size() << std::endl;
searchName = "BranchlessBinarySearchNoPrefetch";
}else if(!strcmp(method, "bfsp")){
// const auto start = std::chrono::high_resolution_clock::now();
ns = util::timing([&]{
for (uint64_t pos = 0; pos < Q.size(); pos++) {
// std::cout << pos << std::endl;
BranchlessBinarySearch<uint64_t>::search(data, Q[pos], 0, A.size()-1);
}
});
// const auto end = std::chrono::high_resolution_clock::now();
// timer = std::chrono::duration_cast<std::chrono::nanoseconds>(end - start).count();
std::cout << "BFS With Prefetch TIME: " << (double)ns/(double)Q.size() << std::endl;
searchName = "BranchlessBinarySearch";
}else if(!strcmp(method, "kbbs")){
// const auto start = std::chrono::high_resolution_clock::now();
if(dataset == "L1_osm_cellids_200M" || dataset == "L2_osm_cellids_200M" || dataset == "L3_osm_cellids_200M"){
rs::Builder<uint64_t>rsb(min,max, 13, 325);
for (const auto& key : A) rsb.AddKey(key);
rs = rsb.Finalize();
}else if(dataset == "L4_osm_cellids_200M"){
rs::Builder<uint64_t>rsb(min,max, 13, 325);
for (const auto& key : A) rsb.AddKey(key);
rs = rsb.Finalize();
}else{
rs::Builder<uint64_t>rsb(min,max);
for (const auto& key : A) rsb.AddKey(key);
rs = rsb.Finalize();
}
ns = util::timing([&]{
rs::SearchBound bound;
uint64_t res = 0;
for (uint64_t pos = 0; pos < Q.size(); pos++) {
if(Q[pos] > A[A.size()-1]){
res = A.size()-1;
}else if(Q[pos] < A[0]){
res = 0;
}else{
bound = rs.GetSearchBound(Q[pos]);
KBBS_Search<uint64_t>::search(data, Q[pos], bound.begin, bound.end,k);
}
}
});
// const auto end = std::chrono::high_resolution_clock::now();
// timer = std::chrono::duration_cast<std::chrono::nanoseconds>(end - start).count();
std::cout << "KBBS With Prefetch TIME: " << (double)ns/(double)Q.size() << std::endl;
searchName = "kbbs";
}else if(!strcmp(method, "kbfs")){
// const auto start = std::chrono::high_resolution_clock::now();
ns = util::timing([&]{
for (uint64_t pos = 0; pos < Q.size(); pos++) {
KBFS_Search<uint64_t>::search(data, Q[pos], 0, A.size()-1, k);
}
});
// const auto end = std::chrono::high_resolution_clock::now();
// timer = std::chrono::duration_cast<std::chrono::nanoseconds>(end - start).count();
std::cout << "KBFS With Prefetch TIME: " << (double)ns/(double)Q.size() << std::endl;
searchName = "kbfs";
}else if(!strcmp(method, "bfep")){
std::vector<Row<uint64_t>> layout;
layout.resize(A.size());
auto start = std::chrono::high_resolution_clock::now();
EytzingerLayoutSearch<uint64_t>::createLayout(data, layout, 0, A.size());
auto end = std::chrono::high_resolution_clock::now();
buildTimer = std::chrono::duration_cast<std::chrono::nanoseconds>(end - start).count();
// start = std::chrono::high_resolution_clock::now();
ns = util::timing([&]{
for (uint64_t pos = 0; pos < Q.size(); pos++) {
EytzingerLayoutSearch<uint64_t>::search(data, Q[pos], 0, A.size()-1);
}
});
// end = std::chrono::high_resolution_clock::now();
// timer = std::chrono::duration_cast<std::chrono::nanoseconds>(end - start).count();
std::cout << "KBFS With Prefetch TIME: " << (double)ns/(double)Q.size() << std::endl;
searchName = "EytzingerLayoutSearch";
}else if(!strcmp(method, "bfe")){
std::vector<Row<uint64_t>> layout;
layout.resize(A.size());
auto start = std::chrono::high_resolution_clock::now();
EytzingerLayoutSearchNoPrefetch<uint64_t>::createLayout(data, layout, 0, A.size());
auto end = std::chrono::high_resolution_clock::now();
buildTimer = std::chrono::duration_cast<std::chrono::nanoseconds>(end - start).count();
// start = std::chrono::high_resolution_clock::now();
ns = util::timing([&]{
for (uint64_t pos = 0; pos < Q.size(); pos++) {
EytzingerLayoutSearchNoPrefetch<uint64_t>::search(data, Q[pos], 0, A.size()-1);
}
});
// end = std::chrono::high_resolution_clock::now();
// timer = std::chrono::duration_cast<std::chrono::nanoseconds>(end - start).count();
std::cout << "KBFS With Prefetch TIME: " << (double)ns/(double)Q.size() << std::endl;
searchName = "EytzingerLayoutSearchNoPrefetch";
}
ss << dataName;
std::string dataNameStr;
ss >> dataNameStr;
ss.clear();
const std::string filename =
"./results/" + dataNameStr + "_results_table.csv";
std::ofstream fout(filename, std::ofstream::out | std::ofstream::app);
if (!fout.is_open()) {
std::cerr << "Failure to print CSV on " << filename << std::endl;
return 1;
}
std::cout << timer << std::endl;
fout << "RS" << "," << 0 << "," << (double)ns/(double)Q.size()
<< "," << 0 << "," << buildTimer/A.size() << "," << searchName
<< "," << dataNameStr << std::endl;
fout.close();
return 0;
}