Bitcoin Core 31.99.0
P2P Digital Currency
lockedpool.cpp
Go to the documentation of this file.
1// Copyright (c) 2016-present The Bitcoin Core developers
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5#include <bench/bench.h>
7// IWYU incorrectly suggests removing this header.
8// See https://github.com/include-what-you-use/include-what-you-use/issues/2014.
9#include <util/byte_units.h> // IWYU pragma: keep
10
11#include <cstddef>
12#include <cstdint>
13#include <vector>
14
15#define ASIZE 2048
16#define MSIZE 2048
17
19{
20 void *synth_base = reinterpret_cast<void*>(0x08000000);
21 const size_t synth_size{1_MiB};
22 Arena b(synth_base, synth_size, 16);
23
24 std::vector<void*> addr{ASIZE, nullptr};
25 uint32_t s = 0x12345678;
26 bench.run([&] {
27 int idx = s & (addr.size() - 1);
28 if (s & 0x80000000) {
29 b.free(addr[idx]);
30 addr[idx] = nullptr;
31 } else if (!addr[idx]) {
32 addr[idx] = b.alloc((s >> 16) & (MSIZE - 1));
33 }
34 bool lsb = s & 1;
35 s >>= 1;
36 if (lsb)
37 s ^= 0xf00f00f0; // LFSR period 0xf7ffffe0
38 });
39 for (void *ptr: addr)
40 b.free(ptr);
41 addr.clear();
42}
43
#define ASIZE
Definition: lockedpool.cpp:15
#define MSIZE
Definition: lockedpool.cpp:16
BENCHMARK(BenchLockedPool)
static void BenchLockedPool(benchmark::Bench &bench)
Definition: lockedpool.cpp:18
void * alloc(size_t size)
Allocate size bytes from this arena.
Definition: lockedpool.cpp:50
void free(void *ptr)
Free a previously allocated chunk of memory.
Definition: lockedpool.cpp:86
Main entry point to nanobench's benchmarking facility.
Definition: nanobench.h:649
Bench & run(char const *benchmarkName, Op &&op)
Repeatedly calls op() based on the configuration, and performs measurements.
Definition: nanobench.h:1308