-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_range_query.cpp
94 lines (80 loc) · 3 KB
/
test_range_query.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
#include "ART.h"
#include <chrono>
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
template <typename key_type>
std::vector<key_type> read_bin(const char* filename) {
std::ifstream inputFile(filename, std::ios::binary);
inputFile.seekg(0, std::ios::end);
const std::streampos fileSize = inputFile.tellg();
inputFile.seekg(0, std::ios::beg);
std::vector<key_type> data(fileSize / sizeof(key_type));
inputFile.read(reinterpret_cast<char*>(data.data()), fileSize);
return data;
}
int main(int argc, char** argv) {
bool verbose = false; // optional argument
int N = 5000000; // optional argument
string input_file; // required argument
// Parse arguments; make sure to increment i by 2 if you consume an argument
for (int i = 1; i < argc;) {
if (string(argv[i]) == "-v") {
verbose = true;
i++;
} else if (string(argv[i]) == "-N") {
N = atoi(argv[i + 1]);
i += 2;
}
}
// read data
// auto keys = read_bin<uint64_t>(input_file.c_str());
std::vector<uint64_t> keys(N, 0);
for(int i = 0; i < N; i ++)keys[i] = i;
// Build tree
ART::ArtNode* tree = NULL;
long long insertion_time = 0;
for (uint64_t i = 0; i < N; i++) {
uint8_t key[8];
ART::loadKey(keys[i], key);
auto start = chrono::high_resolution_clock::now();
ART::insert(tree, &tree, key, 0, keys[i], 8);
auto stop = chrono::high_resolution_clock::now();
auto duration =
chrono::duration_cast<chrono::nanoseconds>(stop - start);
insertion_time += duration.count();
}
if (verbose) {
cout << "Insertion time: " << insertion_time << " ns" << endl;
}
// Query tree
long long query_time = 0;
// Range Queries
for (uint64_t i = 4; i < N / 10; i++) {
uint8_t key[8], key2[8];
ART::loadKey(keys[i], key);
ART::loadKey(std::min((uint64_t)N - 1, keys[i] + 133), key2);
auto start = chrono::high_resolution_clock::now();
ART::Chain* ch = ART::rangelookup(tree, key, 8, key2, 8, 0, 8);
auto stop = chrono::high_resolution_clock::now();
auto duration =
chrono::duration_cast<chrono::nanoseconds>(stop - start);
query_time += duration.count();
// while(!ch->isEmpty()) {
// uint8_t k[8];
// // ART::loadKey(ART::getLeafValue(ch->pop_front()->nodeptr()), k);
// std::cout << ART::getLeafValue(ch->pop_front()->nodeptr()) << ", ";
// }
// std::cout << std::endl;
// auto stop = chrono::high_resolution_clock::now();
// auto duration =
// chrono::duration_cast<chrono::nanoseconds>(stop - start);
// query_time += duration.count();
// assert(ART::isLeaf(leaf) && ART::getLeafValue(leaf) == keys[i]);
}
// simply output the times in csv format
cout << insertion_time << "," << query_time << endl;
return 0;
}