|
Boost : |
Subject: [boost] [object_pool]too slow?
From: jon_zhou_at_[hidden]
Date: 2009-03-09 22:59:04
Dear boost members,
anyony can check the code below? the way that I am using boost/pool is correct?
it is too slow in my "linux 2.6+Intel(R) Core(TM)2 Duo CPU E6850 @ 3.00GHz" pc
thanks!
*********
#include "boost/pool/object_pool.hpp"
#include <sys/time.h>
#include <pthread.h>
#include <asm/atomic.h>
#include <stdlib.h>
class Rational
{
public:
Rational(int a = 0,int b = 1):n(a),d(b)
{
}
private:
int n;
int d;
};
atomic_t gv;
boost::object_pool<Rational> pool;
void *thread_function(void *arg)
{
struct timeval tpstart,tpend;
atomic_t *v=(atomic_t *)arg;
Rational *array[1000];
// Start timing here
gettimeofday(&tpstart,NULL);
for (int j = 0; j < 50000; j++)
{
for (int i = 0; i < 1000; i++)
{
array[i] = pool.construct(i);
}
for (int i = 0; i < 1000; i++)
{
pool.destroy(array[i]);
}
}
gettimeofday(&tpend,NULL);
int timeuse = (tpend.tv_sec-tpstart.tv_sec)*1000000 + (tpend.tv_usec-tpstart.tv_usec);
printf("time= %d usec\n",timeuse);
atomic_add(timeuse, v);
}
int main(int argc,char **argv)
{
if (argc != 2)
{
perror("usuage:Mempool numberOfThreads\n");
exit(-1);
}
/*
* initialize atomic_t
*/
atomic_set(&gv, 0);
char *end;
int numThreads = strtol(argv[1],&end,10);
pthread_t a_thread[numThreads];
void *thread_result;
int res;
for (int i=0; i < numThreads;i++)
{
res = pthread_create(&a_thread[i], NULL, thread_function, (void *)&gv);
}
for (int i=0; i < numThreads;i++)
{
res = pthread_join(a_thread[i], &thread_result);
}
printf("\nTotal time= %d usec\n",gv);
}
Regards,
zhou rui
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk