Boost logo

Boost Users :

Subject: [Boost-users] Object Pool Usage
From: david.weber_at_[hidden]
Date: 2009-09-23 10:42:08


So, I'm investigating Object Pools, and I think I'm not getting
something. The documentation isn't great, hence the question
 
We have a lot of small objects that we will use throughout our
application's lifespan, and I'm trying to see if ObjectPool is a good
fit for us. Heck, I'm just trying to look at performance of it in
general.

So, I have the following code:

--------------------------------------------------------------

void testNormal()
{
    common::Timer t;
    t.start();

    for(int i = 0; i < MAX_NUM_TESTS; i++)
    {
        testClass t;
        t.doWork();
    }
    t.stop();

    std::cout << "No Pool: Creating " << MAX_NUM_TESTS << " took " <<
str_cast(t.getTotalElapsedTime()) << std::endl;
}
 
void testPool()
{
    common::Timer t;
    t.start();
    boost::object_pool<testClass> pool;

    for(int i = 0; i < MAX_NUM_TESTS; i++)
    {
        testClass::ptr tc = pool.construct();
        tc->doWork();
    }

    t.stop();
    std::cout << "Pool: Creating " << MAX_NUM_TESTS << " took " <<
str_cast(t.getTotalElapsedTime()) << std::endl;
}

int main(int argc, char* argv[])
{
    testNormal();
    testPool();

    return 0;
}
------------------------------------------------

When run, I am getting:

No Pool: Creating 500000 took 00:00:00.187785
   Pool: Creating 500000 took 00:00:00.281679

So, I guess I'm not understanding the advantage of the pools. Could
someone write/modify my example to make it make more sense?

Thanks

--dw


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