Raven Core  3.0.0
P2P Digital Currency
lockedpool.cpp
Go to the documentation of this file.
1 // Copyright (c) 2016 The Bitcoin Core developers
2 // Copyright (c) 2017-2019 The Raven Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #include "bench.h"
7 
8 #include "support/lockedpool.h"
9 
10 #include <iostream>
11 #include <vector>
12 
13 #define ASIZE 2048
14 #define BITER 5000
15 #define MSIZE 2048
16 
17 static void BenchLockedPool(benchmark::State& state)
18 {
19  void *synth_base = reinterpret_cast<void*>(0x08000000);
20  const size_t synth_size = 1024*1024;
21  Arena b(synth_base, synth_size, 16);
22 
23  std::vector<void*> addr;
24  for (int x=0; x<ASIZE; ++x)
25  addr.push_back(nullptr);
26  uint32_t s = 0x12345678;
27  while (state.KeepRunning()) {
28  for (int x=0; x<BITER; ++x) {
29  int idx = s & (addr.size()-1);
30  if (s & 0x80000000) {
31  b.free(addr[idx]);
32  addr[idx] = nullptr;
33  } else if(!addr[idx]) {
34  addr[idx] = b.alloc((s >> 16) & (MSIZE-1));
35  }
36  bool lsb = s & 1;
37  s >>= 1;
38  if (lsb)
39  s ^= 0xf00f00f0; // LFSR period 0xf7ffffe0
40  }
41  }
42  for (void *ptr: addr)
43  b.free(ptr);
44  addr.clear();
45 }
46 
47 BENCHMARK(BenchLockedPool);
48 
bool KeepRunning()
Definition: bench.cpp:44
#define ASIZE
Definition: lockedpool.cpp:13
#define BITER
Definition: lockedpool.cpp:14
void * alloc(size_t size)
Allocate size bytes from this arena.
Definition: lockedpool.cpp:58
#define MSIZE
Definition: lockedpool.cpp:15
void free(void *ptr)
Free a previously allocated chunk of memory.
Definition: lockedpool.cpp:89
BENCHMARK(BenchLockedPool)