Skip to content

Commit 444c673

Browse files
committed
bench: Add benchmark for lockedpool allocation/deallocation
1 parent 6567999 commit 444c673

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

src/Makefile.bench.include

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ bench_bench_bitcoin_SOURCES = \
1717
bench/ccoins_caching.cpp \
1818
bench/mempool_eviction.cpp \
1919
bench/verify_script.cpp \
20-
bench/base58.cpp
20+
bench/base58.cpp \
21+
bench/lockedpool.cpp
2122

2223
bench_bench_bitcoin_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) $(EVENT_CLFAGS) $(EVENT_PTHREADS_CFLAGS) -I$(builddir)/bench/
2324
bench_bench_bitcoin_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)

src/bench/lockedpool.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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.h"
6+
7+
#include "support/lockedpool.h"
8+
9+
#include <iostream>
10+
#include <vector>
11+
12+
#define ASIZE 2048
13+
#define BITER 5000
14+
#define MSIZE 2048
15+
16+
static void LockedPool(benchmark::State& state)
17+
{
18+
void *synth_base = reinterpret_cast<void*>(0x08000000);
19+
const size_t synth_size = 1024*1024;
20+
Arena b(synth_base, synth_size, 16);
21+
22+
std::vector<void*> addr;
23+
for (int x=0; x<ASIZE; ++x)
24+
addr.push_back(0);
25+
uint32_t s = 0x12345678;
26+
while (state.KeepRunning()) {
27+
for (int x=0; x<BITER; ++x) {
28+
int idx = s & (addr.size()-1);
29+
if (s & 0x80000000) {
30+
b.free(addr[idx]);
31+
addr[idx] = 0;
32+
} else if(!addr[idx]) {
33+
addr[idx] = b.alloc((s >> 16) & (MSIZE-1));
34+
}
35+
bool lsb = s & 1;
36+
s >>= 1;
37+
if (lsb)
38+
s ^= 0xf00f00f0; // LFSR period 0xf7ffffe0
39+
}
40+
}
41+
for (void *ptr: addr)
42+
b.free(ptr);
43+
addr.clear();
44+
}
45+
46+
BENCHMARK(LockedPool);
47+

0 commit comments

Comments
 (0)