diff --git a/Worksheet2/test3.cpp b/Worksheet2/test3.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ca780e4a73da07edf5ada4674fdf07f6a038b631 --- /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; +}