From 0d790fb7c1a0de75d2c484b527f778acf5ce096d Mon Sep 17 00:00:00 2001 From: Raphael Steiner Date: Fri, 3 Apr 2026 08:18:12 +0200 Subject: [PATCH 1/2] Updated benchmark --- benchmarks/RingBuffer.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/benchmarks/RingBuffer.cpp b/benchmarks/RingBuffer.cpp index 319b596..befb070 100644 --- a/benchmarks/RingBuffer.cpp +++ b/benchmarks/RingBuffer.cpp @@ -28,7 +28,7 @@ using namespace spapq; constexpr std::size_t capacity = 1U << 10; constexpr int64_t numItems = 1 << 20; constexpr unsigned seed = 42U; -constexpr bool randomValues = true; +constexpr bool randomValues = false; constexpr std::size_t producerCpu = 0; constexpr std::size_t consumerCpu = 1; @@ -61,16 +61,16 @@ static void BM_RingBuffer_1Threads_alternating(benchmark::State &state) { for (std::size_t i = 0; i < values.size(); ++i) { values[i] = static_cast(std::rand()); } for (auto _ : state) { - std::optional popVal(std::nullopt); for (std::size_t i = 0U; i < values.size(); ++i) { if constexpr (randomValues) { while (not channel.push(values[i])) { } } else { while (not channel.push(i)) { } } - while (not (popVal = channel.pop())) { } + std::size_t val = 0U; + while (not channel.pop(val)) { } + benchmark::DoNotOptimize(val); } - benchmark::DoNotOptimize(popVal); benchmark::ClobberMemory(); } @@ -89,8 +89,6 @@ static void BM_RingBuffer_1Threads_random(benchmark::State &state) { for (std::size_t i = 0; i < values.size(); ++i) { values[i] = static_cast(std::rand()); } for (auto _ : state) { - std::optional popVal(std::nullopt); - std::size_t pushCntr = 0U; std::size_t popCntr = 0U; while (pushCntr < values.size() || popCntr < values.size()) { @@ -103,6 +101,7 @@ static void BM_RingBuffer_1Threads_random(benchmark::State &state) { producer = ((j * static_cast(691U)) & static_cast(8U)) == static_cast(0U); } + std::size_t val = 0U; if (producer) { if constexpr (randomValues) { if (pushCntr < values.size() && channel.push((values[pushCntr]))) { @@ -116,14 +115,14 @@ static void BM_RingBuffer_1Threads_random(benchmark::State &state) { } } } else { - if (popCntr < values.size() && (popVal = channel.pop())) { + if (popCntr < values.size() && channel.pop(val)) { ++popCntr; break; } } + benchmark::DoNotOptimize(val); } } - benchmark::DoNotOptimize(popVal); benchmark::ClobberMemory(); } From 4e2b4a5d458e9a2e3e5c99eb752b137e37ef657b Mon Sep 17 00:00:00 2001 From: Raphael Steiner Date: Fri, 3 Apr 2026 08:29:57 +0200 Subject: [PATCH 2/2] updated SpapQueue to reference --- include/ParallelPriorityQueue/SpapQueueWorker.hpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/include/ParallelPriorityQueue/SpapQueueWorker.hpp b/include/ParallelPriorityQueue/SpapQueueWorker.hpp index f408513..e219fa5 100644 --- a/include/ParallelPriorityQueue/SpapQueueWorker.hpp +++ b/include/ParallelPriorityQueue/SpapQueueWorker.hpp @@ -314,10 +314,9 @@ inline void WorkerResource::pushOutBufferSelf template inline void WorkerResource::enqueueInChannels() noexcept { for (auto &portRingBuffer : inPorts_) { - std::optional data = portRingBuffer.pop(); - while (data.has_value()) { - queue_.push(*data); - data = portRingBuffer.pop(); + value_type data; + while (portRingBuffer.pop(data)) { + queue_.push(data); } } }