Compare commits
3 Commits
c4c269ab94
...
main
Author | SHA1 | Date | |
---|---|---|---|
6abd8139f0 | |||
57cceaf3b7 | |||
39273424c1 |
113
Bench.cpp
113
Bench.cpp
@@ -3,6 +3,34 @@
|
|||||||
|
|
||||||
#include <nanobench.h>
|
#include <nanobench.h>
|
||||||
|
|
||||||
|
void iterBench(const Facade &facade, int64_t version,
|
||||||
|
const std::string &context) {
|
||||||
|
ankerl::nanobench::Bench bench;
|
||||||
|
bench.minEpochIterations(10000);
|
||||||
|
|
||||||
|
const auto begin = facade.versioned.begin(version);
|
||||||
|
const auto end = facade.versioned.end(version);
|
||||||
|
auto iter = begin;
|
||||||
|
|
||||||
|
bench.run("*iter (" + context + ")", [&] { bench.doNotOptimizeAway(*iter); });
|
||||||
|
|
||||||
|
iter = begin;
|
||||||
|
bench.run("++iter (" + context + ")", [&] {
|
||||||
|
++iter;
|
||||||
|
if (iter == end) {
|
||||||
|
iter = begin;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
iter = end;
|
||||||
|
bench.run("--iter (" + context + ")", [&] {
|
||||||
|
--iter;
|
||||||
|
if (iter == begin) {
|
||||||
|
iter = end;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
void monotonicallyIncreasing() {
|
void monotonicallyIncreasing() {
|
||||||
constexpr int kWindow = 1000;
|
constexpr int kWindow = 1000;
|
||||||
ankerl::nanobench::Bench bench;
|
ankerl::nanobench::Bench bench;
|
||||||
@@ -25,27 +53,7 @@ void monotonicallyIncreasing() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const auto v = facade.getVersion() - kWindow / 2;
|
const auto v = facade.getVersion() - kWindow / 2;
|
||||||
const auto begin = facade.versioned.begin(v);
|
iterBench(facade, v, "monotonically increasing");
|
||||||
const auto end = facade.versioned.end(v);
|
|
||||||
auto iter = begin;
|
|
||||||
|
|
||||||
bench.run("*iter", [&] { bench.doNotOptimizeAway(*iter); });
|
|
||||||
|
|
||||||
iter = begin;
|
|
||||||
bench.run("++iter", [&] {
|
|
||||||
++iter;
|
|
||||||
if (iter == end) {
|
|
||||||
iter = begin;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
iter = end;
|
|
||||||
bench.run("--iter", [&] {
|
|
||||||
--iter;
|
|
||||||
if (iter == begin) {
|
|
||||||
iter = end;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
bench.run("begin", [&] { facade.versioned.begin(v); });
|
bench.run("begin", [&] { facade.versioned.begin(v); });
|
||||||
|
|
||||||
@@ -56,6 +64,27 @@ void monotonicallyIncreasing() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
bench.run("end", [&] { facade.versioned.end(v); });
|
bench.run("end", [&] { facade.versioned.end(v); });
|
||||||
|
|
||||||
|
{
|
||||||
|
ankerl::nanobench::Bench bench;
|
||||||
|
bench.batch(kWindow);
|
||||||
|
|
||||||
|
bench.run("Facade monotonically-increasing read forward", [&]() {
|
||||||
|
if (facade.viewAt(facade.getVersion())
|
||||||
|
.rangeRead(String(), String({0xff}), kWindow, false)
|
||||||
|
.size() != kWindow) {
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
bench.run("Facade monotonically-increasing read reverse", [&]() {
|
||||||
|
if (facade.viewAt(facade.getVersion())
|
||||||
|
.rangeRead(String(), String({0xff}), kWindow, true)
|
||||||
|
.size() != kWindow) {
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void bulkFirstGeq() {
|
void bulkFirstGeq() {
|
||||||
@@ -105,7 +134,7 @@ void bulkFirstGeq() {
|
|||||||
|
|
||||||
void facadeVersionedOnlyRead() {
|
void facadeVersionedOnlyRead() {
|
||||||
Facade facade{0};
|
Facade facade{0};
|
||||||
constexpr int kNumKeys = 10000;
|
constexpr int kNumKeys = 1000;
|
||||||
ankerl::nanobench::Bench bench;
|
ankerl::nanobench::Bench bench;
|
||||||
bench.batch(kNumKeys);
|
bench.batch(kNumKeys);
|
||||||
|
|
||||||
@@ -125,35 +154,39 @@ void facadeVersionedOnlyRead() {
|
|||||||
facade.getVersion() + 1);
|
facade.getVersion() + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add keys
|
Arena arena;
|
||||||
|
weaselab::VersionedMap::Mutation *mutations =
|
||||||
|
new (arena) weaselab::VersionedMap::Mutation[kNumKeys];
|
||||||
for (int i = 0; i < kNumKeys; ++i) {
|
for (int i = 0; i < kNumKeys; ++i) {
|
||||||
const int64_t k = __builtin_bswap64(i);
|
const int64_t k = __builtin_bswap64(i);
|
||||||
weaselab::VersionedMap::Mutation mutations[] = {
|
uint8_t *buf = new (arena) uint8_t[8];
|
||||||
{(const uint8_t *)&k, 8, (const uint8_t *)&k, 8,
|
memcpy(buf, &k, 8);
|
||||||
weaselab::VersionedMap::Set},
|
mutations[i] = {buf, 8, buf, 8, weaselab::VersionedMap::Set};
|
||||||
};
|
|
||||||
facade.addMutations(mutations, sizeof(mutations) / sizeof(mutations[0]),
|
|
||||||
facade.getVersion() + 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add keys
|
||||||
|
facade.addMutations(mutations, kNumKeys, facade.getVersion() + 1);
|
||||||
|
|
||||||
// Populate the unversioned map
|
// Populate the unversioned map
|
||||||
for (int i = 0; i < kNumKeys; ++i) {
|
facade.addMutations(mutations, kNumKeys, facade.getVersion() + 1);
|
||||||
const int64_t k = __builtin_bswap64(i);
|
|
||||||
weaselab::VersionedMap::Mutation mutations[] = {
|
|
||||||
{(const uint8_t *)&k, 8, (const uint8_t *)&k, 8,
|
|
||||||
weaselab::VersionedMap::Set},
|
|
||||||
};
|
|
||||||
facade.addMutations(mutations, sizeof(mutations) / sizeof(mutations[0]),
|
|
||||||
facade.getVersion() + 1);
|
|
||||||
}
|
|
||||||
facade.setOldestVersion(facade.getVersion() - 1, /*force*/ true);
|
facade.setOldestVersion(facade.getVersion() - 1, /*force*/ true);
|
||||||
|
|
||||||
|
iterBench(facade, facade.getVersion(), "adjacent sets/clears");
|
||||||
|
|
||||||
bench.run("Facade versioned-only read forward", [&]() {
|
bench.run("Facade versioned-only read forward", [&]() {
|
||||||
facade.viewAt(facade.getVersion()).rangeRead(begin, end, kNumKeys, false);
|
if (facade.viewAt(facade.getVersion())
|
||||||
|
.rangeRead(begin, end, kNumKeys, false)
|
||||||
|
.size() != kNumKeys) {
|
||||||
|
abort();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
bench.run("Facade versioned-only read reverse", [&]() {
|
bench.run("Facade versioned-only read reverse", [&]() {
|
||||||
facade.viewAt(facade.getVersion()).rangeRead(begin, end, kNumKeys, true);
|
if (facade.viewAt(facade.getVersion())
|
||||||
|
.rangeRead(begin, end, kNumKeys, true)
|
||||||
|
.size() != kNumKeys) {
|
||||||
|
abort();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -3,11 +3,11 @@
|
|||||||
#include "VersionedMap.h"
|
#include "VersionedMap.h"
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
|
||||||
inline weaselab::VersionedMap::Key operator"" _k(const char *str, size_t size) {
|
inline weaselab::VersionedMap::Key operator""_k(const char *str, size_t size) {
|
||||||
return {reinterpret_cast<const uint8_t *>(str), int(size)};
|
return {reinterpret_cast<const uint8_t *>(str), int(size)};
|
||||||
}
|
}
|
||||||
|
|
||||||
inline String operator"" _s(const char *str, size_t size) {
|
inline String operator""_s(const char *str, size_t size) {
|
||||||
return String{reinterpret_cast<const uint8_t *>(str), size};
|
return String{reinterpret_cast<const uint8_t *>(str), size};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1220,20 +1220,20 @@ VersionedMap::Iterator::operator*() const {
|
|||||||
|
|
||||||
void materializeMutations(VersionedMap::Iterator::Impl *impl,
|
void materializeMutations(VersionedMap::Iterator::Impl *impl,
|
||||||
const Entry *prev) {
|
const Entry *prev) {
|
||||||
if (prev == nullptr) {
|
|
||||||
Finger copy;
|
|
||||||
impl->finger.copyTo(copy);
|
|
||||||
impl->map->move<std::memory_order_acquire, false>(copy, impl->version);
|
|
||||||
if (copy.searchPathSize() > 0) {
|
|
||||||
prev = impl->map->mm.base[copy.backNode()].entry;
|
|
||||||
} else {
|
|
||||||
assert(!impl->map->mm.base[impl->finger.backNode()].entry->clearTo());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const auto &entry = *impl->map->mm.base[impl->finger.backNode()].entry;
|
const auto &entry = *impl->map->mm.base[impl->finger.backNode()].entry;
|
||||||
impl->mutationCount = 0;
|
impl->mutationCount = 0;
|
||||||
if (entry.clearTo()) {
|
if (entry.clearTo()) {
|
||||||
|
if (prev == nullptr) {
|
||||||
|
Finger copy;
|
||||||
|
impl->finger.copyTo(copy);
|
||||||
|
impl->map->move<std::memory_order_acquire, false>(copy, impl->version);
|
||||||
|
if (copy.searchPathSize() > 0) {
|
||||||
|
prev = impl->map->mm.base[copy.backNode()].entry;
|
||||||
|
} else {
|
||||||
|
assert(!impl->map->mm.base[impl->finger.backNode()].entry->clearTo());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl->mutations[impl->mutationCount++] = {
|
impl->mutations[impl->mutationCount++] = {
|
||||||
prev->getKey(),
|
prev->getKey(),
|
||||||
entry.getKey(),
|
entry.getKey(),
|
||||||
|
Reference in New Issue
Block a user