Bitcoin Core  27.99.0
P2P Digital Currency
lockedpool.cpp
Go to the documentation of this file.
1 // Copyright (c) 2016-2022 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>
6 
7 #include <support/lockedpool.h>
8 
9 #include <vector>
10 
11 #define ASIZE 2048
12 #define MSIZE 2048
13 
14 static void BenchLockedPool(benchmark::Bench& bench)
15 {
16  void *synth_base = reinterpret_cast<void*>(0x08000000);
17  const size_t synth_size = 1024*1024;
18  Arena b(synth_base, synth_size, 16);
19 
20  std::vector<void*> addr{ASIZE, nullptr};
21  uint32_t s = 0x12345678;
22  bench.run([&] {
23  int idx = s & (addr.size() - 1);
24  if (s & 0x80000000) {
25  b.free(addr[idx]);
26  addr[idx] = nullptr;
27  } else if (!addr[idx]) {
28  addr[idx] = b.alloc((s >> 16) & (MSIZE - 1));
29  }
30  bool lsb = s & 1;
31  s >>= 1;
32  if (lsb)
33  s ^= 0xf00f00f0; // LFSR period 0xf7ffffe0
34  });
35  for (void *ptr: addr)
36  b.free(ptr);
37  addr.clear();
38 }
39 
#define ASIZE
Definition: lockedpool.cpp:11
#define MSIZE
Definition: lockedpool.cpp:12
static void BenchLockedPool(benchmark::Bench &bench)
Definition: lockedpool.cpp:14
BENCHMARK(BenchLockedPool, benchmark::PriorityLevel::HIGH)
void * alloc(size_t size)
Allocate size bytes from this arena.
Definition: lockedpool.cpp:53
void free(void *ptr)
Free a previously allocated chunk of memory.
Definition: lockedpool.cpp:89
Main entry point to nanobench's benchmarking facility.
Definition: nanobench.h:627
Bench & run(char const *benchmarkName, Op &&op)
Repeatedly calls op() based on the configuration, and performs measurements.
Definition: nanobench.h:1234
@ HIGH
Definition: bench.h:47