Add standalone bench target

This commit is contained in:
2024-02-06 15:03:54 -08:00
parent 9a80c96533
commit 6be23803a3
3 changed files with 51 additions and 26 deletions

45
Bench.cpp Normal file
View File

@@ -0,0 +1,45 @@
#include "ConflictSet.h"
#define ANKERL_NANOBENCH_IMPLEMENT
#include "third_party/nanobench.h"
std::string toKey(int n) {
std::string result;
result.resize(32);
for (int i = 0; i < 32; ++i) {
result[i] = n & (1 << (31 - i)) ? '1' : '0';
}
return result;
}
constexpr int kNumKeys = 100000;
int main(void) {
ankerl::nanobench::Bench bench;
int readKey = kNumKeys / 2;
ConflictSet cs(0);
for (int i = 0; i < kNumKeys; ++i) {
if (i != readKey) {
continue;
}
auto key = toKey(i);
ConflictSet::WriteRange w;
w.begin.p = (const uint8_t *)key.data();
w.begin.len = key.size();
w.end.len = 0;
w.writeVersion = 1;
cs.addWrites(&w, 1);
}
auto key = toKey(readKey);
ConflictSet::ReadRange r;
r.begin.p = (const uint8_t *)key.data();
r.begin.len = key.size();
r.end.len = 0;
r.readVersion = 0;
ConflictSet::Result result;
bench.run("point read", [&]() { cs.check(&r, &result, 1); });
}