// step1/test.cpp #include <assert.h> #include <stdlib.h> #include <time.h> #include <new> #include <memory> #include <iostream> #include "memory_pool.h" #if defined(_STLP_INTERNAL_ALLOC_H) #define single_client_alloc __node_alloc<false,0> #elif defined(__GNUC__) #if __GNUC__ >= 3 #define single_client_alloc __single_client_alloc #endif #else #error "STL implementation not recognized" #endif #ifndef LOOPS #define LOOPS 50000000 #endif #ifndef BLKSIZE #define BLKSIZE 100 #endif using namespace std; void* volatile ptr; int main() { clock_t t; int i; t = clock(); for (i = 0; i < LOOPS; ++i) { ptr = operator new(BLKSIZE); operator delete((void*)ptr); } cout << (clock() - t) * 1.0 / CLOCKS_PER_SEC << endl; t = clock(); for (i = 0; i < LOOPS; ++i) { ptr = single_client_alloc::allocate(BLKSIZE); single_client_alloc::deallocate((void*)ptr, BLKSIZE); } cout << (clock() - t) * 1.0 / CLOCKS_PER_SEC << endl; t = clock(); for (i = 0; i < LOOPS; ++i) { ptr = MemoryPool<BLKSIZE>::allocate(); MemoryPool<BLKSIZE>::deallocate((void*)ptr); } cout << (clock() - t) * 1.0 / CLOCKS_PER_SEC << endl; return 0; }