#include <iostream>
#include <string>
using namespace std;
#include <windows.h>
#include <boost/pool/pool.hpp>
class VM
{
public:
void* operator new(size_t s)
{
return bpool.malloc();
}
void operator delete(void *p)
{
bpool.free(p);
}
private:
char sz[100];
private:
static boost::pool<> bpool;
};
boost::pool<> VM::bpool(sizeof(VM));
class NVM
{
private:
char sz[100];
};
template <class Ty>
DWORD PoolingTest()
{
enum { COUNT = 1000, LOOP = 500 };
DWORD dw = GetTickCount();
Ty *pArr[LOOP];
int i, j;
for (i = 0; i < COUNT; ++i) {
for (j = 0; j < LOOP; ++j) {
pArr[j] = new Ty();
}
for (j = 0; j < LOOP; ++j) {
delete pArr[j];
}
}
return GetTickCount() - dw;
}
int main()
{
cout << "pooling: " << PoolingTest<VM>() << endl;
cout << "normal: " << PoolingTest<NVM>() << endl;
cout << "END" << endl;
cin.get();
return 0;
}
컴파일 환경
CPU: P3 600 (notebook) RAM: 320 gcc version 3.4.1 (mingw special)
결과
pooling: 100 normal: 581 END
'Dev > C++' 카테고리의 다른 글
| Is Derived - code (0) | 2008.05.01 |
|---|---|
| C++에서 프로퍼티 구현하기 (0) | 2008.05.01 |
| STLport 초간단 설치 (1) | 2008.05.01 |
| Stroustrup - The real interview (0) | 2008.05.01 |
| qsort vs sort (0) | 2008.05.01 |