|
Boost Users : |
From: Klaus Nowikow (nowikow_at_[hidden])
Date: 2004-07-01 06:18:15
Hi!
I am in the process of writing a program which has to
handle large numbers (~200000 - 400000) objects of the same class.
These objects will be created and deleted frequently, so I thought
some kind of specialized memory management would be handy.
I wrote a test program (see below) to check what boost.pool would gain
me. The results make me think that I have done something wrong:
debug mode:
std::allocator 2.17s
boost::pool_allocator 7.18s
release mode:
std::allocator 0.11s
boost::pool_allocator 0.36s
i.e., std::allocator was more than 3 times faster than
boost::pool_allocator (Win2k, 256MB). Any ideas what i have done wrong? See the test
program below.
// MemoryPoolTest.cpp
// Boost includes -------------------------------------------------------------
#include <boost/timer.hpp>
#include <boost/pool/pool_alloc.hpp>
// Std includes ---------------------------------------------------------------
#include <vector>
#include <iostream>
enum
{
NUM_ELEMENTS = 3000000
};
template <class Allocator>
double Test()
{
std::vector<Allocator::value_type, Allocator> Vector;
boost::timer Timer;
for(int i = 0; i < NUM_ELEMENTS; ++i)
{
Vector.push_back(i);
}
return Timer.elapsed();
}
int main(int argc, char* argv[])
{
std::cout << "Starting memory pool test" << std::endl;
double Time;
std::cout << "Allocating with boost::pool_allocator<>: ";
Time = Test<boost::pool_allocator<int> >();
std::cout << Time << "s" << std::endl;
std::cout << "Allocating with std::allocator<> : ";
Time = Test<std::allocator<int> >();
std::cout << Time << "s" << std::endl;
return 0;
}
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net