From 40e1ffd3ec70625be4cb19df9c481b13f81ec38a Mon Sep 17 00:00:00 2001
From: j2-pelczar <jakub2.pelczar@live.uwe.ac.uk>
Date: Wed, 27 Nov 2024 21:38:41 +0000
Subject: [PATCH] Upload New File

---
 worksheet_two/task_3/test_bump_allocator.cpp | 36 ++++++++++++++++++++
 1 file changed, 36 insertions(+)
 create mode 100644 worksheet_two/task_3/test_bump_allocator.cpp

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 0000000..8ff1d5e
--- /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;
+}
-- 
GitLab