Boost logo

Boost Users :

From: Xu, Peng (peng.xu_at_[hidden])
Date: 2007-04-18 13:48:16


What kind of optimization did you use? I modified your code to use my timer, and here's the result

"
test(true)
loops=100000 realtime=15393us systime=0us usrtime=10000us waittime=5393us avgRealtimePerLoop=0.15393us avgSystimePerLoop=0us avgUsrtimePerLoop=0.1us avgWaittimePerLoop=0.05393us

test(false)
loops=100000 realtime=20022us systime=0us usrtime=20000us waittime=22us avgRealtimePerLoop=0.20022us avgSystimePerLoop=0us avgUsrtimePerLoop=0.2us avgWaittimePerLoop=0.00022us
"

My compiler is icc 9.1.047, with O3 optimization flags

-----Original Message-----
From: boost-users-bounces_at_[hidden] on behalf of Aubrey, Jason
Sent: Wed 4/18/2007 12:12 PM
To: boost-users_at_[hidden]
Subject: [Boost-users] [Pool][singleton_pool] Performance problem or badusage?
 
Hi,

I've created a helper class called MemoryPooled to help add pooling to
some of my classes; however, the performance seems slow by comparison to
non-pooled behavior. My code is shown below, I suspect I'm doing
something wrong but I don't see how it can be my class. Does anyone
have any idea?

-Jason

// Begin code --------------------------------------
#include <Utilities/stopwatch.h>

#include <boost/pool/singleton_pool.hpp>
#include <boost/shared_ptr.hpp>

#include <iostream>

template<typename T>
class MemoryPooled : public T
{
public:
    MemoryPooled(){}
    virtual ~MemoryPooled(){}

    static const int countObjectsInitiallyAllocated = 1000;
    typedef boost::singleton_pool<T, countObjectsInitiallyAllocated>
Pool;

    void* operator new(size_t /*p_memSize*/)
    {
        return Pool::malloc();
    }

    void operator delete(void* p_memBlock)
    {
        Pool::free(p_memBlock);
    }
};

struct Test1
{
   int i0; int i1; int i2; int i3; int i4;
   int i5; int i6; int i7; int i8; int i9;
};

void test(bool p_isPooled)
{
    Utilities::StopWatch sw; // Stopwatch is my helper for getting times
    sw.start();
    for(int i=0; i < 100000; ++i)
    {
        if( p_isPooled )
            boost::shared_ptr<Test1> item(new MemoryPooled<Test1>());
        else
            boost::shared_ptr<Test1> item(new Test1());
    }
    const double elapsed = sw.elapsedTime();
    cout << "Elapsed time: " << elapsed << " ms" << endl;
}

int main(int, char**)
{
    test(true);
    test(false);
}
// End code --------------------------------------

Output:
     Elapsed time: 106.812 ms (Pooled)
     Elapsed time: 94.2158 ms (Not Pooled)


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