dash/src/bench/lockedpool.cpp
MarcoFalke 4a3e3af6e7
Merge #20813: scripted-diff: Bump copyright headers
fa0074e2d82928016a43ca408717154a1c70a4db scripted-diff: Bump copyright headers (MarcoFalke)

Pull request description:

  Needs to be done because no one has removed the years yet

ACKs for top commit:
  practicalswift:
    ACK fa0074e2d82928016a43ca408717154a1c70a4db

Tree-SHA512: 210e92acd7d400b556cf8259c3ec9967797420cfd19f0c2a4fa54cb2b3d32ad9ae27e771269201e7d554c0f4cd73a8b1c1a42c9f65d8685ca4d52e5134b071a3
2024-04-10 03:19:34 +07:00

43 lines
1.1 KiB
C++

// Copyright (c) 2016-2020 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <bench/bench.h>
#include <support/lockedpool.h>
#include <vector>
#define ASIZE 2048
#define MSIZE 2048
static void BenchLockedPool(benchmark::Bench& bench)
{
void *synth_base = reinterpret_cast<void*>(0x08000000);
const size_t synth_size = 1024*1024;
Arena b(synth_base, synth_size, 16);
std::vector<void*> addr;
for (int x=0; x<ASIZE; ++x)
addr.push_back(nullptr);
uint32_t s = 0x12345678;
bench.run([&] {
int idx = s & (addr.size() - 1);
if (s & 0x80000000) {
b.free(addr[idx]);
addr[idx] = nullptr;
} else if (!addr[idx]) {
addr[idx] = b.alloc((s >> 16) & (MSIZE - 1));
}
bool lsb = s & 1;
s >>= 1;
if (lsb)
s ^= 0xf00f00f0; // LFSR period 0xf7ffffe0
});
for (void *ptr: addr)
b.free(ptr);
addr.clear();
}
BENCHMARK(BenchLockedPool);