Bitcoin Core
32.1.0
P2P Digital Currency
Toggle main menu visibility
Loading...
Searching...
No Matches
src
bench
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
>
6
#include <
support/lockedpool.h
>
7
#include <
util/byte_units.h
>
8
9
#include <cstddef>
10
#include <cstdint>
11
#include <vector>
12
13
#define ASIZE 2048
14
#define MSIZE 2048
15
16
static
void
BenchLockedPool
(
benchmark::Bench
& bench)
17
{
18
void
*synth_base =
reinterpret_cast<
void
*
>
(0x08000000);
19
const
size_t
synth_size{1_MiB};
20
Arena
b(synth_base, synth_size, 16);
21
22
std::vector<void*> addr{
ASIZE
,
nullptr
};
23
uint32_t s = 0x12345678;
24
bench.
run
([&] {
25
int
idx = s & (addr.size() - 1);
26
if
(s & 0x80000000) {
27
b.
free
(addr[idx]);
28
addr[idx] =
nullptr
;
29
}
else
if
(!addr[idx]) {
30
addr[idx] = b.
alloc
((s >> 16) & (
MSIZE
- 1));
31
}
32
bool
lsb = s & 1;
33
s >>= 1;
34
if
(lsb)
35
s ^= 0xf00f00f0;
// LFSR period 0xf7ffffe0
36
});
37
for
(
void
*ptr: addr)
38
b.
free
(ptr);
39
addr.clear();
40
}
41
42
BENCHMARK
(
BenchLockedPool
);
bench.h
BENCHMARK
#define BENCHMARK(n)
Definition
bench.h:69
ASIZE
#define ASIZE
Definition
lockedpool.cpp:13
MSIZE
#define MSIZE
Definition
lockedpool.cpp:14
BenchLockedPool
static void BenchLockedPool(benchmark::Bench &bench)
Definition
lockedpool.cpp:16
byte_units.h
Arena
Definition
lockedpool.h:49
Arena::alloc
void * alloc(size_t size)
Allocate size bytes from this arena.
Definition
lockedpool.cpp:50
Arena::free
void free(void *ptr)
Free a previously allocated chunk of memory.
Definition
lockedpool.cpp:86
ankerl::nanobench::Bench
Main entry point to nanobench's benchmarking facility.
Definition
nanobench.h:649
ankerl::nanobench::Bench::run
Bench & run(char const *benchmarkName, Op &&op)
Repeatedly calls op() based on the configuration, and performs measurements.
Definition
nanobench.h:1308
lockedpool.h
Generated on
for Bitcoin Core by
1.18.0