Skip to content
Snippets Groups Projects
Commit 40e1ffd3 authored by j2-pelczar's avatar j2-pelczar :cowboy:
Browse files

Upload New File

parent 617ebd0b
No related branches found
No related tags found
No related merge requests found
#include "benchmark.hpp"
#include "bump_allocator.hpp"
void testAllocateUp(BumpAllocator& allocator, std::size_t iterations, std::size_t allocSize) {
for (std::size_t i = 0; i < iterations; ++i) {
allocator.allocateUp(allocSize);
}
allocator.reset();
}
void testAllocateDown(BumpAllocator& allocator, std::size_t iterations, std::size_t allocSize) {
for (std::size_t i = 0; i < iterations; ++i) {
allocator.allocateDown(allocSize);
}
allocator.reset();
}
int main() {
const std::size_t memorySize = 1024 * 1024; // 1 MB
const std::size_t allocSize = 64; // 64 bytes per allocation
const std::size_t iterations = 10000; // Number of allocations
BumpAllocator allocator(memorySize);
// Benchmark bump up allocator
Benchmark::measure("Bump Up Allocator", [&]() {
testAllocateUp(allocator, iterations, allocSize);
});
// Benchmark bump down allocator
Benchmark::measure("Bump Down Allocator", [&]() {
testAllocateDown(allocator, iterations, allocSize);
});
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment