diff --git a/worksheet_two/task_3/test_bump_allocator.cpp b/worksheet_two/task_3/test_bump_allocator.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8ff1d5ef6c01348363a0b9c34f30dbdd49c512a6 --- /dev/null +++ b/worksheet_two/task_3/test_bump_allocator.cpp @@ -0,0 +1,36 @@ +#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; +}