Measure across different cardinalities for radix worst case bench
This commit is contained in:
51
Bench.cpp
51
Bench.cpp
@@ -258,16 +258,13 @@ void benchConflictSet() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void benchWorstCaseForRadixRangeRead() {
|
constexpr int kKeyLenForWorstCase = 50;
|
||||||
ankerl::nanobench::Bench bench;
|
|
||||||
|
ConflictSet worstCaseConflictSetForRadixRangeRead(int cardinality) {
|
||||||
ConflictSet cs{0};
|
ConflictSet cs{0};
|
||||||
|
|
||||||
int64_t version = 0;
|
for (int i = 0; i < kKeyLenForWorstCase; ++i) {
|
||||||
|
for (int j = 0; j < cardinality; ++j) {
|
||||||
constexpr int kKeyLength = 50;
|
|
||||||
|
|
||||||
for (int i = 0; i < kKeyLength; ++i) {
|
|
||||||
for (int j = 0; j < 256; ++j) {
|
|
||||||
auto b = std::vector<uint8_t>(i, 0);
|
auto b = std::vector<uint8_t>(i, 0);
|
||||||
b.push_back(j);
|
b.push_back(j);
|
||||||
auto e = std::vector<uint8_t>(i, 255);
|
auto e = std::vector<uint8_t>(i, 255);
|
||||||
@@ -280,48 +277,62 @@ void benchWorstCaseForRadixRangeRead() {
|
|||||||
{e.data(), int(e.size())},
|
{e.data(), int(e.size())},
|
||||||
{nullptr, 0},
|
{nullptr, 0},
|
||||||
}};
|
}};
|
||||||
cs.addWrites(w, sizeof(w) / sizeof(w[0]), version);
|
cs.addWrites(w, sizeof(w) / sizeof(w[0]), 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Defeat short-circuiting on the left
|
// Defeat short-circuiting on the left
|
||||||
{
|
{
|
||||||
auto k = std::vector<uint8_t>(kKeyLength, 0);
|
auto k = std::vector<uint8_t>(kKeyLenForWorstCase, 0);
|
||||||
weaselab::ConflictSet::WriteRange w[] = {
|
weaselab::ConflictSet::WriteRange w[] = {
|
||||||
{
|
{
|
||||||
{k.data(), int(k.size())},
|
{k.data(), int(k.size())},
|
||||||
{nullptr, 0},
|
{nullptr, 0},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
cs.addWrites(w, sizeof(w) / sizeof(w[0]), 2);
|
cs.addWrites(w, sizeof(w) / sizeof(w[0]), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Defeat short-circuiting on the right
|
// Defeat short-circuiting on the right
|
||||||
{
|
{
|
||||||
auto k = std::vector<uint8_t>(kKeyLength, 255);
|
auto k = std::vector<uint8_t>(kKeyLenForWorstCase, 255);
|
||||||
weaselab::ConflictSet::WriteRange w[] = {
|
weaselab::ConflictSet::WriteRange w[] = {
|
||||||
{
|
{
|
||||||
{k.data(), int(k.size())},
|
{k.data(), int(k.size())},
|
||||||
{nullptr, 0},
|
{nullptr, 0},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
cs.addWrites(w, sizeof(w) / sizeof(w[0]), 2);
|
cs.addWrites(w, sizeof(w) / sizeof(w[0]), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto begin = std::vector<uint8_t>(kKeyLength - 1, 0);
|
return cs;
|
||||||
|
}
|
||||||
|
|
||||||
|
void benchWorstCaseForRadixRangeRead() {
|
||||||
|
ankerl::nanobench::Bench bench;
|
||||||
|
|
||||||
|
std::unique_ptr<ConflictSet> cs[256];
|
||||||
|
for (int i = 0; i < 256; ++i) {
|
||||||
|
cs[i] =
|
||||||
|
std::make_unique<ConflictSet>(worstCaseConflictSetForRadixRangeRead(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
auto begin = std::vector<uint8_t>(kKeyLenForWorstCase - 1, 0);
|
||||||
begin.push_back(1);
|
begin.push_back(1);
|
||||||
auto end = std::vector<uint8_t>(kKeyLength - 1, 255);
|
auto end = std::vector<uint8_t>(kKeyLenForWorstCase - 1, 255);
|
||||||
end.push_back(254);
|
end.push_back(254);
|
||||||
|
|
||||||
weaselab::ConflictSet::Result result;
|
weaselab::ConflictSet::Result result;
|
||||||
weaselab::ConflictSet::ReadRange r{
|
weaselab::ConflictSet::ReadRange r{
|
||||||
{begin.data(), int(begin.size())}, {end.data(), int(end.size())}, 1};
|
{begin.data(), int(begin.size())}, {end.data(), int(end.size())}, 0};
|
||||||
|
|
||||||
bench.run("worst case for radix tree", [&]() {
|
bench.run("worst case for radix tree", [&]() {
|
||||||
result = weaselab::ConflictSet::TooOld;
|
for (int i = 0; i < 256; ++i) {
|
||||||
cs.check(&r, &result, 1);
|
result = weaselab::ConflictSet::TooOld;
|
||||||
if (result != weaselab::ConflictSet::Commit) {
|
cs[i]->check(&r, &result, 1);
|
||||||
abort();
|
if (result != weaselab::ConflictSet::Commit) {
|
||||||
|
abort();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user