2016-11-02 11:16:19 +01:00
|
|
|
// Copyright (c) 2016 The Bitcoin Core developers
|
|
|
|
// Distributed under the MIT software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
2020-03-19 23:46:56 +01:00
|
|
|
#include <bench/bench.h>
|
2016-11-02 11:16:19 +01:00
|
|
|
|
2020-03-19 23:46:56 +01:00
|
|
|
#include <support/lockedpool.h>
|
2016-11-02 11:16:19 +01:00
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#define ASIZE 2048
|
|
|
|
#define MSIZE 2048
|
|
|
|
|
2021-06-26 12:03:16 +02:00
|
|
|
static void BenchLockedPool(benchmark::Bench& bench)
|
2016-11-02 11:16:19 +01:00
|
|
|
{
|
|
|
|
void *synth_base = reinterpret_cast<void*>(0x08000000);
|
|
|
|
const size_t synth_size = 1024*1024;
|
|
|
|
Arena b(synth_base, synth_size, 16);
|
|
|
|
|
|
|
|
std::vector<void*> addr;
|
|
|
|
for (int x=0; x<ASIZE; ++x)
|
2017-08-16 15:54:51 +02:00
|
|
|
addr.push_back(nullptr);
|
2016-11-02 11:16:19 +01:00
|
|
|
uint32_t s = 0x12345678;
|
2021-06-26 12:03:16 +02:00
|
|
|
bench.run([&] {
|
|
|
|
int idx = s & (addr.size() - 1);
|
|
|
|
if (s & 0x80000000) {
|
|
|
|
b.free(addr[idx]);
|
|
|
|
addr[idx] = nullptr;
|
|
|
|
} else if (!addr[idx]) {
|
|
|
|
addr[idx] = b.alloc((s >> 16) & (MSIZE - 1));
|
2016-11-02 11:16:19 +01:00
|
|
|
}
|
2021-06-26 12:03:16 +02:00
|
|
|
bool lsb = s & 1;
|
|
|
|
s >>= 1;
|
|
|
|
if (lsb)
|
|
|
|
s ^= 0xf00f00f0; // LFSR period 0xf7ffffe0
|
|
|
|
});
|
2016-11-02 11:16:19 +01:00
|
|
|
for (void *ptr: addr)
|
|
|
|
b.free(ptr);
|
|
|
|
addr.clear();
|
|
|
|
}
|
|
|
|
|
2021-06-26 12:03:16 +02:00
|
|
|
BENCHMARK(BenchLockedPool);
|