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.
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.