Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions benchmarks/RingBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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::size_t>(std::rand()); }

for (auto _ : state) {
std::optional<std::size_t> 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();
}

Expand All @@ -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::size_t>(std::rand()); }

for (auto _ : state) {
std::optional<std::size_t> popVal(std::nullopt);

std::size_t pushCntr = 0U;
std::size_t popCntr = 0U;
while (pushCntr < values.size() || popCntr < values.size()) {
Expand All @@ -103,6 +101,7 @@ static void BM_RingBuffer_1Threads_random(benchmark::State &state) {
producer = ((j * static_cast<std::size_t>(691U)) & static_cast<std::size_t>(8U)) == static_cast<std::size_t>(0U);
}

std::size_t val = 0U;
if (producer) {
if constexpr (randomValues) {
if (pushCntr < values.size() && channel.push((values[pushCntr]))) {
Expand All @@ -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();
}

Expand Down
7 changes: 3 additions & 4 deletions include/ParallelPriorityQueue/SpapQueueWorker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,10 +314,9 @@ inline void WorkerResource<GlobalQType, LocalQType, numPorts>::pushOutBufferSelf
template <typename GlobalQType, BasicQueue LocalQType, std::size_t numPorts>
inline void WorkerResource<GlobalQType, LocalQType, numPorts>::enqueueInChannels() noexcept {
for (auto &portRingBuffer : inPorts_) {
std::optional<value_type> data = portRingBuffer.pop();
while (data.has_value()) {
queue_.push(*data);
data = portRingBuffer.pop();
value_type data;
while (portRingBuffer.pop(data)) {
queue_.push(data);
}
}
}
Expand Down