2024-03-01 16:30:51 -05:00
|
|
|
#include <chrono>
|
|
|
|
#include <iostream>
|
|
|
|
|
2024-03-01 15:19:52 -05:00
|
|
|
#include "tests.hpp"
|
2024-03-01 14:21:52 -05:00
|
|
|
|
|
|
|
int main() {
|
2024-03-01 15:19:52 -05:00
|
|
|
tests t;
|
|
|
|
t.runTests();
|
2024-03-01 16:30:51 -05:00
|
|
|
|
|
|
|
auto startSlow{std::chrono::high_resolution_clock::now()};
|
|
|
|
stub *ptr{};
|
|
|
|
for (size_t i{}; i < 10000; i++) {
|
|
|
|
ptr = new stub();
|
|
|
|
delete ptr;
|
|
|
|
}
|
|
|
|
auto endSlow{std::chrono::high_resolution_clock::now()};
|
|
|
|
|
|
|
|
std::cout << "Time (milliseconds) required for allocations without pool: " <<
|
|
|
|
std::chrono::duration_cast<std::chrono::milliseconds>(endSlow - startSlow).count() << "\n";
|
|
|
|
|
|
|
|
auto startAlloc{std::chrono::high_resolution_clock::now()};
|
|
|
|
allocPool<stub> a(10000);
|
|
|
|
auto endAlloc{std::chrono::high_resolution_clock::now()};
|
|
|
|
|
|
|
|
auto startFast{std::chrono::high_resolution_clock::now()};
|
|
|
|
for (size_t i{}; i < 10000; i++) {
|
|
|
|
ptr = a.getPtr();
|
|
|
|
a.returnPtr(ptr);
|
|
|
|
}
|
|
|
|
auto endFast{std::chrono::high_resolution_clock::now()};
|
|
|
|
|
|
|
|
std::cout << "Time (milliseconds) required for allocations with pool: " <<
|
|
|
|
std::chrono::duration_cast<std::chrono::milliseconds>(endFast - startFast).count() << "\n";
|
|
|
|
|
|
|
|
std::cout << "Time (milliseconds) required for real allocations when constructing pool: " <<
|
|
|
|
std::chrono::duration_cast<std::chrono::milliseconds>(endAlloc - startAlloc).count() << "\n";
|
|
|
|
|
2024-03-01 14:21:52 -05:00
|
|
|
return 0;
|
|
|
|
}
|