Bitcoin Core  0.19.99
P2P Digital Currency
lockedpool.cpp
Go to the documentation of this file.
1 // Copyright (c) 2016-2019 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 BITER 5000
13 #define MSIZE 2048
14 
15 static void BenchLockedPool(benchmark::State& state)
16 {
17  void *synth_base = reinterpret_cast<void*>(0x08000000);
18  const size_t synth_size = 1024*1024;
19  Arena b(synth_base, synth_size, 16);
20 
21  std::vector<void*> addr;
22  for (int x=0; x<ASIZE; ++x)
23  addr.push_back(nullptr);
24  uint32_t s = 0x12345678;
25  while (state.KeepRunning()) {
26  for (int x=0; x<BITER; ++x) {
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  }
40  for (void *ptr: addr)
41  b.free(ptr);
42  addr.clear();
43 }
44 
BENCHMARK(BenchLockedPool, 1300)
bool KeepRunning()
Definition: bench.h:72
#define ASIZE
Definition: lockedpool.cpp:11
#define BITER
Definition: lockedpool.cpp:12
void * alloc(size_t size)
Allocate size bytes from this arena.
Definition: lockedpool.cpp:59
static void BenchLockedPool(benchmark::State &state)
Definition: lockedpool.cpp:15
#define MSIZE
Definition: lockedpool.cpp:13
void free(void *ptr)
Free a previously allocated chunk of memory.
Definition: lockedpool.cpp:94