lockedpool.cpp raw
1 // Copyright (c) 2016-2022 The Limenka 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
8 #include <cstddef>
9 #include <cstdint>
10 #include <vector>
11
12 #define ASIZE 2048
13 #define MSIZE 2048
14
15 static void BenchLockedPool(benchmark::Bench& bench)
16 {
17 void *synth_base = reinterpret_cast<void*>(0x08000000);
18 const size_t synth_size = 1024*1024;
19 Arena b(synth_base, synth_size, 16);
20
21 std::vector<void*> addr{ASIZE, nullptr};
22 uint32_t s = 0x12345678;
23 bench.run([&] {
24 int idx = s & (addr.size() - 1);
25 if (s & 0x80000000) {
26 b.free(addr[idx]);
27 addr[idx] = nullptr;
28 } else if (!addr[idx]) {
29 addr[idx] = b.alloc((s >> 16) & (MSIZE - 1));
30 }
31 bool lsb = s & 1;
32 s >>= 1;
33 if (lsb)
34 s ^= 0xf00f00f0; // LFSR period 0xf7ffffe0
35 });
36 for (void *ptr: addr)
37 b.free(ptr);
38 addr.clear();
39 }
40
41 BENCHMARK(BenchLockedPool, benchmark::PriorityLevel::HIGH);
42