Defeat shared_ptr's single-threaded optimizations
WeaselDB is always going to start multiple threads, so we don't care about single-threaded performance
This commit is contained in:
@@ -43,9 +43,16 @@ template <typename T> struct PointerTraits<Ref<T>> {
|
||||
static const char *weak_name() { return "WeakRef"; }
|
||||
};
|
||||
|
||||
// Force multi-threaded mode to defeat __libc_single_threaded optimization
|
||||
void force_multithreaded() {
|
||||
std::thread t([]() {});
|
||||
t.join();
|
||||
}
|
||||
|
||||
template <typename PtrType>
|
||||
void benchmark_creation(ankerl::nanobench::Bench &bench) {
|
||||
using Traits = PointerTraits<PtrType>;
|
||||
force_multithreaded();
|
||||
|
||||
bench.run(std::string(Traits::name()) + " creation", [&] {
|
||||
auto ptr = Traits::make(TestObject{123});
|
||||
@@ -56,6 +63,7 @@ void benchmark_creation(ankerl::nanobench::Bench &bench) {
|
||||
template <typename PtrType>
|
||||
void benchmark_copy(ankerl::nanobench::Bench &bench) {
|
||||
using Traits = PointerTraits<PtrType>;
|
||||
force_multithreaded();
|
||||
|
||||
auto original = Traits::make(TestObject{123});
|
||||
bench.run(std::string(Traits::name()) + " copy", [&] {
|
||||
@@ -80,6 +88,7 @@ void benchmark_move(ankerl::nanobench::Bench &bench) {
|
||||
template <typename PtrType>
|
||||
void benchmark_weak_copy(ankerl::nanobench::Bench &bench) {
|
||||
using Traits = PointerTraits<PtrType>;
|
||||
force_multithreaded();
|
||||
|
||||
auto strong_ptr = Traits::make(TestObject{123});
|
||||
typename Traits::weak_type weak_original = strong_ptr;
|
||||
|
||||
Reference in New Issue
Block a user