boost fast_pool_allocator performance question

A

absurd

Hello,

I have a very simple program trying to see how well the boost fast
pool allocator is, but I don't get good results.

My program looks like,

main.cpp

#include <iostream>
#include <list>
#include <iterator>
#include <boost/pool/pool_alloc.hpp>

#include "Clock.h"

int CNT = 0;
unsigned int NUM = 1000000;

template <typename L>
void test_list( L & l )
{
Clock clock( CNT++);
for ( int i = 0; i < 3; i++ )
{
for (int j = 0; j < NUM; ++j)
{
typename L::value_type obj(j);
l.push_back( obj );
}


template <unsigned int SIZE>
struct Bytes
{
char bytes[SIZE];
Bytes( unsigned int i ) {}
};


int main()
{
std::list< Bytes<4> > l;
test_list( l );

std::list<int, boost::fast_pool_allocator<Bytes<4> > > pl;
test_list( pl );
}


Clock.h


#ifndef CLOCK_H
#define CLOCK_H
#include <iostream>

class Clock
{
public:
static long long diff( const timespec & start, const timespec &
end )
{
return (( end.tv_sec - start.tv_sec ) * 1000000000 +
( end.tv_nsec - start.tv_nsec )) / 1000;
}

Clock( int id )
: m_id( id )
{
clock_gettime( CLOCK_PROCESS_CPUTIME_ID, &m_start );
//clock_gettime( CLOCK_THREAD_CPUTIME_ID, &m_start );
}

~Clock()
{
clock_gettime( CLOCK_PROCESS_CPUTIME_ID, &m_end );
std::cout << "t," << m_id << "," << diff( m_start, m_end ) <<
std::endl;
}

private:
int m_id;
timespec m_start;
timespec m_end;

};

#endif


results,
$ ./a.out
t,0,181820
t,1,266289

As you see from the above results, boost version is significantly
slower. Am I using the boost allocator correctly ?

Thanks.
 
A

absurd

Correction:

The following line :
std::list<int, boost::fast_pool_allocator<Bytes<4> > > pl;

should be
std::list< Bytes<4>, boost::fast_pool_allocator<Bytes<4> > > pl;
 
A

Abhishek Padmanabh

Hello,

I have a very simple program trying to see how well the boost fast
pool allocator is, but I don't get good results.

My program looks like,

main.cpp

#include <iostream>
#include <list>
#include <iterator>
#include <boost/pool/pool_alloc.hpp>

#include "Clock.h"

int CNT = 0;
unsigned int NUM = 1000000;

template <typename L>
void test_list( L & l )
{
    Clock clock( CNT++);
    for ( int i = 0; i < 3; i++ )
    {
        for (int j = 0; j < NUM; ++j)
        {
            typename L::value_type obj(j);
            l.push_back( obj );
        }

Your test is just allocating objects into the list. That is not the
case for which the pool allocators are suggested for. They are
designed for use when you have frequent allocations as well as
deallocations. So, to simulate that you would need also to remove
elements from the list and re-insert and so on. The current slowness
could be because of the underlying pool that the allocator needs to
maintain.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top