Skip to content

Commit 4ece3e8

Browse files
author
Can Gokmen
committed
Implemented preloading
1 parent 5ebc52d commit 4ece3e8

1 file changed

Lines changed: 37 additions & 2 deletions

File tree

test_kfp.cpp

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,31 @@ int main() {
7878
uint8_t key[keyBytes];
7979
long long kfp_ns, art_ns;
8080

81+
// Fraction of keys to pre-load (not timed) before the measured insertion run.
82+
static constexpr double PRELOAD_FRAC = 0.5;
83+
const size_t preload_total = static_cast<size_t>(3.0 * N * PRELOAD_FRAC);
84+
cout << "Pre-loading " << preload_total << " keys (" << (PRELOAD_FRAC*100) << "%) before timed run\n\n";
85+
8186
// ── QuART_kfp<3> ─────────────────────────────────────────────────────────
8287
{
8388
QuART_kfp<3> tree;
8489
size_t pos[3] = {0, 0, 0};
8590
mt19937 rng(42);
8691

92+
// Pre-load phase (not timed)
93+
for (size_t i = 0; i < preload_total; ) {
94+
int active[3], na = 0;
95+
for (int w = 0; w < 3; w++) if (pos[w] < N) active[na++] = w;
96+
if (!na) break;
97+
int w = active[uniform_int_distribution<int>(0, na - 1)(rng)];
98+
key_int_t k = files[w].data[pos[w]++];
99+
encodeKey(k, key);
100+
tree.insert(key, k);
101+
++i;
102+
}
103+
104+
// Timed phase
105+
const size_t timed_keys = 3 * N - preload_total;
87106
auto t0 = chrono::high_resolution_clock::now();
88107
while (true) {
89108
int active[3], na = 0;
@@ -112,7 +131,8 @@ int main() {
112131
}
113132
cout << "QuART_kfp<3>: " << kfp_ns / 1'000'000 << " ms"
114133
<< " (" << fixed << setprecision(1)
115-
<< (double)(3*N) / (kfp_ns / 1e9) / 1e6 << " M inserts/s)\n";
134+
<< (double)timed_keys / (kfp_ns / 1e9) / 1e6 << " M inserts/s, "
135+
<< timed_keys << " timed keys)\n";
116136
#ifdef QUART_KFP_STATS
117137
long long total = tree.getFpInsertCount() + tree.getBridgeCount() + tree.getNoMatchCount();
118138
cout << " FP_INSERT=" << tree.getFpInsertCount()
@@ -129,6 +149,20 @@ int main() {
129149
size_t pos[3] = {0, 0, 0};
130150
mt19937 rng(42); // same seed → identical sequence
131151

152+
// Pre-load phase (not timed)
153+
for (size_t i = 0; i < preload_total; ) {
154+
int active[3], na = 0;
155+
for (int w = 0; w < 3; w++) if (pos[w] < N) active[na++] = w;
156+
if (!na) break;
157+
int w = active[uniform_int_distribution<int>(0, na - 1)(rng)];
158+
key_int_t k = files[w].data[pos[w]++];
159+
encodeKey(k, key);
160+
tree.insert(key, k);
161+
++i;
162+
}
163+
164+
// Timed phase
165+
const size_t timed_keys = 3 * N - preload_total;
132166
auto t0 = chrono::high_resolution_clock::now();
133167
while (true) {
134168
int active[3], na = 0;
@@ -144,7 +178,8 @@ int main() {
144178

145179
cout << "ART: " << art_ns / 1'000'000 << " ms"
146180
<< " (" << fixed << setprecision(1)
147-
<< (double)(3*N) / (art_ns / 1e9) / 1e6 << " M inserts/s)\n";
181+
<< (double)timed_keys / (art_ns / 1e9) / 1e6 << " M inserts/s, "
182+
<< timed_keys << " timed keys)\n";
148183
}
149184

150185
cout << "\nSpeedup (QuART_kfp / ART): " << fixed << setprecision(2)

0 commit comments

Comments
 (0)