From fe63e89f5bc493f2a8e71dc7d971b22e076fdc86 Mon Sep 17 00:00:00 2001 From: j2-tulloch <james2.tulloch@live.uwe.ac.uk> Date: Wed, 20 Dec 2023 21:01:08 +0000 Subject: [PATCH] Upload New File --- Worksheet2/test3.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 Worksheet2/test3.cpp diff --git a/Worksheet2/test3.cpp b/Worksheet2/test3.cpp new file mode 100644 index 0000000..ca780e4 --- /dev/null +++ b/Worksheet2/test3.cpp @@ -0,0 +1,33 @@ +#include <chrono> +#include <iostream> +#include "bumpalld.hpp" +//#include "bumpall.hpp" + +void benchmarkBumpAllocator() { + const size_t blockSize = 1000000; // Size of the memory block + BumpAllocator allocator(blockSize); + + // Example allocation/deallocation operations + for (int i = 0; i < 10000; ++i) { + allocator.allocate(100); // Allocate 100 bytes + allocator.reset(); // Reset the allocator for the next iteration + } +} + +int main() { + using std::chrono::high_resolution_clock; + using std::chrono::duration_cast; + using std::chrono::duration; + using std::chrono::milliseconds; + + auto t1 = high_resolution_clock::now(); + benchmarkBumpAllocator(); + auto t2 = high_resolution_clock::now(); + + auto ms_int = duration_cast<milliseconds>(t2 - t1); + duration<double, std::milli> ms_double = t2 - t1; + + std::cout << ms_int.count() << "ms\n"; + std::cout << ms_double.count() << "ms\n"; + return 0; +} -- GitLab