Skip to content

Commit 2e796da

Browse files
committed
Added QuART_tail stuff
1 parent 4c41f12 commit 2e796da

5 files changed

Lines changed: 153 additions & 6 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
**/*.csv
22
build/
3-
.DS_Store
3+
.DS_Store
4+
results/

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ set(CMAKE_CXX_FLAGS_DEBUG "-g -O0")
1717
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
1818
add_executable(main main.cpp)
1919
add_executable(test_range test_range_query.cpp)
20+
add_executable(run run.cpp)

run.cpp

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
#include <algorithm>
2+
#include <chrono>
3+
#include <fstream>
4+
#include <iostream>
5+
#include <vector>
6+
7+
#include "ART.h"
8+
#include "ArtNode.h"
9+
#include "ArtNodeNewMethods.cpp"
10+
#include "Chain.h"
11+
#include "Helper.h"
12+
#include "trees/QuART_tail.h"
13+
14+
using namespace std;
15+
16+
template <typename key_type>
17+
std::vector<key_type> read_bin(const char* filename) {
18+
std::ifstream inputFile(filename, std::ios::binary);
19+
inputFile.seekg(0, std::ios::end);
20+
const std::streampos fileSize = inputFile.tellg();
21+
inputFile.seekg(0, std::ios::beg);
22+
std::vector<key_type> data(fileSize / sizeof(key_type));
23+
inputFile.read(reinterpret_cast<char*>(data.data()), fileSize);
24+
return data;
25+
}
26+
27+
int main(int argc, char** argv) {
28+
bool verbose = false; // optional argument
29+
int N = 5000000; // optional argument
30+
string input_file; // required argument
31+
string tree_type = "ART"; // default tree type
32+
33+
// Parse arguments; make sure to increment i by 2 if you consume an argument
34+
for (int i = 1; i < argc;) {
35+
if (string(argv[i]) == "-v") {
36+
verbose = true;
37+
i++;
38+
} else if (string(argv[i]) == "-N") {
39+
N = atoi(argv[i + 1]);
40+
i += 2;
41+
} else if (string(argv[i]) == "-f") {
42+
input_file = argv[i + 1];
43+
i += 2;
44+
} else if (string(argv[i]) == "-t") {
45+
tree_type = argv[i + 1];
46+
i += 2;
47+
} else {
48+
i++;
49+
}
50+
}
51+
52+
// read data
53+
auto keys = read_bin<uint32_t>(input_file.c_str());
54+
55+
// Build tree
56+
ART::ART* tree = nullptr;
57+
if (tree_type == "ART") {
58+
tree = new ART::ART();
59+
} else if (tree_type == "QuART_tail") {
60+
tree = new ART::QuART_tail();
61+
} else {
62+
cerr << "Unknown tree type: " << tree_type << endl;
63+
return 1;
64+
}
65+
66+
if (verbose) {
67+
cout << "Tree type: " << tree_type << endl;
68+
}
69+
70+
long long insertion_time = 0;
71+
for (uint64_t i = 0; i < N; i++) {
72+
uint8_t key[4];
73+
ART::loadKey(keys[i], key);
74+
auto start = chrono::high_resolution_clock::now();
75+
tree->insert(key, keys[i]);
76+
auto stop = chrono::high_resolution_clock::now();
77+
auto duration =
78+
chrono::duration_cast<chrono::nanoseconds>(stop - start);
79+
insertion_time += duration.count();
80+
}
81+
82+
if (verbose) {
83+
cout << "Insertion time: " << insertion_time << " ns" << endl;
84+
}
85+
86+
// Query tree
87+
long long query_time = 0;
88+
for (uint64_t i = 0; i < N; i++) {
89+
uint8_t key[4];
90+
ART::loadKey(keys[i], key);
91+
auto start = chrono::high_resolution_clock::now();
92+
ART::ArtNode* leaf = tree->lookup(key);
93+
auto stop = chrono::high_resolution_clock::now();
94+
auto duration =
95+
chrono::duration_cast<chrono::nanoseconds>(stop - start);
96+
query_time += duration.count();
97+
assert(ART::isLeaf(leaf) && ART::getLeafValue(leaf) == keys[i]);
98+
}
99+
100+
if (verbose) {
101+
cout << "Query time: " << query_time << " ns" << endl;
102+
}
103+
104+
// Output the times in csv format, including tree type
105+
cout << insertion_time << "," << query_time << endl;
106+
107+
return 0;
108+
}

run_experiments.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/bash
2+
SUFFIX=$(date +"%Y%m%d_%H%M%S")
3+
RESULTSDIR="results"
4+
RESULTS="${RESULTSDIR}/results_${SUFFIX}.txt"
5+
LOGDIR="${RESULTSDIR}/logs"
6+
7+
mkdir -p "$LOGDIR"
8+
9+
echo "N,K,L,type_of_tree,avg_insert_time,avg_query_time" > "$RESULTS"
10+
11+
REPEAT=1
12+
13+
for FILE in ../bods/workloads/workload_N*_K*_L*.bin; do
14+
[ -f "$FILE" ] || continue
15+
16+
BASENAME=$(basename "$FILE")
17+
N=$(echo "$BASENAME" | sed -n 's/.*_N\([0-9]*\)_K[0-9]*_L[0-9]*.bin/\1/p')
18+
K=$(echo "$BASENAME" | sed -n 's/.*_N[0-9]*_K\([0-9]*\)_L[0-9]*.bin/\1/p')
19+
L=$(echo "$BASENAME" | sed -n 's/.*_N[0-9]*_K[0-9]*_L\([0-9]*\).bin/\1/p')
20+
LOGFILE="${LOGDIR}/log_${BASENAME%.txt}_${SUFFIX}.txt"
21+
22+
for TREE in ART QuART_tail; do
23+
INSERT_SUM=0
24+
QUERY_SUM=0
25+
26+
for ((i=1; i<=REPEAT; i++)); do
27+
echo "Running $TREE on $FILE (run $i/$REPEAT)" >> "$LOGFILE"
28+
OUTPUT=$(./build/run -v -f "$FILE" -N "$N" -t "$TREE" 2>>"$LOGFILE")
29+
echo "$OUTPUT" >> "$LOGFILE"
30+
CSV_LINE=$(echo "$OUTPUT" | tail -1)
31+
INSERT_TIME=$(echo "$CSV_LINE" | cut -d',' -f1 | xargs)
32+
QUERY_TIME=$(echo "$CSV_LINE" | cut -d',' -f2 | xargs)
33+
INSERT_SUM=$((INSERT_SUM + INSERT_TIME))
34+
QUERY_SUM=$((QUERY_SUM + QUERY_TIME))
35+
done
36+
37+
AVG_INSERT_TIME=$((INSERT_SUM / REPEAT))
38+
AVG_QUERY_TIME=$((QUERY_SUM / REPEAT))
39+
echo "$N,$K,$L,$TREE,$AVG_INSERT_TIME,$AVG_QUERY_TIME" >> "$RESULTS"
40+
done
41+
done

trees/QuART_tail.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
#pragma once
22

3-
#include "ART.h"
4-
#include "ArtNode.h"
5-
6-
namespace ART {
7-
3+
namespace ART {
84
class QuART_tail : public ART {
95
public:
106

0 commit comments

Comments
 (0)