Still need a better way identify left/right sidedness

This commit is contained in:
2024-02-09 15:17:37 -08:00
parent f3e7279c2c
commit 80a79aab1f
3 changed files with 108 additions and 19 deletions

View File

@@ -1,4 +1,5 @@
#include "ConflictSet.h"
#include "Internal.h"
#define ANKERL_NANOBENCH_IMPLEMENT
#include "third_party/nanobench.h"
@@ -15,7 +16,7 @@ std::string toKey(int n) {
constexpr int kNumKeys = 100000;
int main(void) {
void benchPointRead() {
ankerl::nanobench::Bench bench;
int readKey = kNumKeys / 2;
@@ -42,4 +43,66 @@ int main(void) {
r.readVersion = 0;
ConflictSet::Result result;
bench.run("point read", [&]() { cs.check(&r, &result, 1); });
}
void benchPointerSet() {
ankerl::nanobench::Bench bench;
constexpr int kNumPointers = 32;
bench.batch(kNumPointers);
std::vector<void *> pointers;
for (int i = 0; i < kNumPointers; ++i) {
pointers.push_back(malloc(1));
}
bench.run("Create and destroy Arena hashset", [&]() {
Arena arena;
auto h = hashSet<void *>(arena);
for (auto p : pointers) {
h.insert(p);
}
});
bench.run("Create and destroy malloc hashset", [&]() {
std::unordered_set<void *, MyHash<void *>> h;
for (auto p : pointers) {
h.insert(p);
}
});
bench.run("Create and destroy Arena vector", [&]() {
Arena arena;
auto h = vector<void *>(arena);
for (auto p : pointers) {
h.push_back(p);
}
});
{
Arena arena;
auto h = hashSet<void *>(arena);
bench.run("Find hashset", [&]() {
for (auto p : pointers) {
bench.doNotOptimizeAway(h.find(p));
}
});
}
{
bench.run("Find vector", [&]() {
for (auto p : pointers) {
bench.doNotOptimizeAway(std::find(pointers.begin(), pointers.end(), p));
}
});
}
for (auto p : pointers) {
free(p);
}
}
int main(void) {
// benchPointRead();
benchPointerSet();
}