Skip to content

Instantly share code, notes, and snippets.

@alkis
Last active August 29, 2018 11:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alkis/73535b313dacfa5c6d2f0987f0d72875 to your computer and use it in GitHub Desktop.
Save alkis/73535b313dacfa5c6d2f0987f0d72875 to your computer and use it in GitHub Desktop.
template <class Sync>
void Sequence(benchmark::State& state) {
static Sync sync;
static std::atomic<uint64> pseq{0};
static uint64 cseq{0};
std::priority_queue<int, std::vector<int>, std::greater<int>> queue;
typename Sync::Mem mem;
for (auto _ : state) {
uint64 p = pseq.fetch_add(std::memory_order_relaxed);
sync.Run(&mem, [&, p] {
queue.push(p);
uint64 c = cseq;
while (!queue.empty() && c == queue.top()) {
++c;
queue.pop();
}
cseq = c;
});
}
}
// Benchmark Time(ns) CPU(ns) Iterations
// -----------------------------------------------------------------------------------
// Sequence<ActionChainNoPooling>/threads:1 61.8 61.8 9789886
// Sequence<ActionChainNoPooling>/threads:4 95.9 308 2092948
// Sequence<ActionChainNoPooling>/threads:12 73.9 499 1200000
// Sequence<ActionChainNoPooling>/threads:16 69.5 488 1423632
// Sequence<ActionChainNoPooling>/threads:128 64.7 444 1280000
// Sequence<ActionChain>/threads:1 38.4 38.4 16257661
// Sequence<ActionChain>/threads:4 79.4 250 2352984
// Sequence<ActionChain>/threads:12 64.6 455 1200000
// Sequence<ActionChain>/threads:16 63.3 434 1600000
// Sequence<ActionChain>/threads:128 67.3 470 1280000
// Sequence<CriticalSection>/threads:1 29.5 29.5 22470611
// Sequence<CriticalSection>/threads:4 157 600 949304
// Sequence<CriticalSection>/threads:12 214 1656 409992
// Sequence<CriticalSection>/threads:16 195 1463 457056
// Sequence<CriticalSection>/threads:128 188 1289 540032
// Sequence<Unsynchronized> 23.0 23.3 33835886
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment