Add standalone bench target
This commit is contained in:
45
Bench.cpp
Normal file
45
Bench.cpp
Normal 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); });
|
||||||
|
}
|
@@ -171,6 +171,11 @@ if(BUILD_TESTING)
|
|||||||
${CMAKE_SOURCE_DIR}/test_symbols.sh
|
${CMAKE_SOURCE_DIR}/test_symbols.sh
|
||||||
$<TARGET_FILE:${PROJECT_NAME}_static> ${CMAKE_SOURCE_DIR}/symbols.txt)
|
$<TARGET_FILE:${PROJECT_NAME}_static> ${CMAKE_SOURCE_DIR}/symbols.txt)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
# bench
|
||||||
|
|
||||||
|
add_executable(conflict_set_bench Bench.cpp)
|
||||||
|
target_link_libraries(conflict_set_bench PRIVATE ${PROJECT_NAME})
|
||||||
endif()
|
endif()
|
||||||
# packaging
|
# packaging
|
||||||
|
|
||||||
|
@@ -1178,30 +1178,6 @@ void __throw_length_error(const char *) { __builtin_unreachable(); }
|
|||||||
} // namespace std
|
} // namespace std
|
||||||
|
|
||||||
#ifdef ENABLE_MAIN
|
#ifdef ENABLE_MAIN
|
||||||
#define ANKERL_NANOBENCH_IMPLEMENT
|
|
||||||
#include "third_party/nanobench.h"
|
|
||||||
|
|
||||||
void bench() {
|
|
||||||
ankerl::nanobench::Bench bench;
|
|
||||||
{
|
|
||||||
auto *n = newNode();
|
|
||||||
for (int i = 0; i < 64; ++i) {
|
|
||||||
getOrCreateChild(n, i) = newNode();
|
|
||||||
bench.run("getChildLeq" + std::to_string(i),
|
|
||||||
[&]() { bench.doNotOptimizeAway(getChildLeq(n, 255)); });
|
|
||||||
}
|
|
||||||
destroyTree(n);
|
|
||||||
}
|
|
||||||
{
|
|
||||||
auto *n = newNode();
|
|
||||||
for (int i = 255; i >= 3 * 64; --i) {
|
|
||||||
getOrCreateChild(n, i) = newNode();
|
|
||||||
bench.run("getChildGeq" + std::to_string(i),
|
|
||||||
[&]() { bench.doNotOptimizeAway(getChildGeq(n, 0)); });
|
|
||||||
}
|
|
||||||
destroyTree(n);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void printTree() {
|
void printTree() {
|
||||||
int64_t writeVersion = 0;
|
int64_t writeVersion = 0;
|
||||||
@@ -1224,8 +1200,7 @@ void printTree() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
bench();
|
printTree();
|
||||||
// printTree();
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user