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