[Dune] [Dune-Commit] dune-common r5258 - trunk/common/test

Martin Nolte nolte at mathematik.uni-freiburg.de
Sat Aug 2 10:29:10 CEST 2008


Hi Markus,

you're right, pool allocator seems nearly 20% faster. I think the reason is that 
SmallObject stores the size of the object while pool allocator does not need to 
(yes, we are talking about writing one integer to memory). The question is, can 
we remove the SmallObjectPool and replace it by your pool allocator? This would 
reduce the amount of doubled code.

I think the SmallObject (not the pool) is still a good idea because by adding 
one derivation to your object, the new / delete mechanism will instantaneously 
be almost as fast as using the pool allocator (and there I have to create an 
instance and exchange every new / delete in my code...)

Cheers,

Martin

mblatt at dune-project.org wrote:
> Author: mblatt
> Date: 2008-08-02 01:21:19 +0200 (Sat, 02 Aug 2008)
> New Revision: 5258
> 
> Modified:
>    trunk/common/test/smallobject.cc
> Log:
> I was curious and added comparison to pool allocator, which seems faster.
> 
> 
> Modified: trunk/common/test/smallobject.cc
> ===================================================================
> --- trunk/common/test/smallobject.cc	2008-08-01 23:19:24 UTC (rev 5257)
> +++ trunk/common/test/smallobject.cc	2008-08-01 23:21:19 UTC (rev 5258)
> @@ -4,6 +4,7 @@
>  
>  #include <dune/common/timer.hh>
>  #include <dune/common/smallobject.hh>
> +#include <dune/common/poolallocator.hh>
>  
>  using namespace Dune;
>  
> @@ -34,7 +35,7 @@
>  {
>    Timer timer;
>  
> -  const unsigned long iterations = 1 << 30;
> +  const unsigned long iterations = 1 << 26;
>    std :: cout << "Performing " << iterations << " iterations." << std :: endl;
>  
>    timer.reset();
> @@ -51,9 +52,21 @@
>    {
>      B *b = new B( (int)i );
>      delete b;
> -  }
> +  } 
>    double timeB = timer.elapsed();
>    std :: cout << "Time with SmallObject: " << timeB << std :: endl;
> +  std :: cout << "Result: SmallObject is " << (timeA / timeB) << " times faster." << std :: endl;
>  
> -  std :: cout << "Result: SmallObject is " << (timeA / timeB) << " times faster." << std :: endl;
> +  timer.reset();
> +  PoolAllocator<B,100> pool;
> +  for( unsigned long i = 0; i < iterations; ++i )
> +  {
> +    B *b = pool.allocate(1);
> +    pool.construct(b, B((int)i ));
> +    pool.destroy(b);
> +    pool.deallocate(b,1);
> +  }
> +  double timeB2 = timer.elapsed();
> +  std :: cout << "Time with pool allocator: " << timeB2 << std :: endl;
> +  std :: cout << "Result: pool allocator is " << (timeA / timeB2) << " times faster." << std :: endl;
>  }
> 
> 
> _______________________________________________
> Dune-Commit mailing list
> Dune-Commit at dune-project.org
> http://lists.dune-project.org/mailman/listinfo/dune-commit

-- 
Martin Nolte <nolte at mathematik.uni-freiburg.de>

Universität Freiburg                                   phone: +49-761-203-5642
Abteilung für angewandte Mathematik                    fax:   +49-761-203-5632
Hermann-Herder-Straße 10
79104 Freiburg, Germany




More information about the Dune mailing list