On 01/05/2017 06:44 PM, Phil Bouchard wrote:
On 01/05/2017 07:26 AM, Phil Bouchard wrote:
Simon was mentioning that it would be preferable having root_ptr with an
underlying mechanism to select memory pools based on the type allocated
or the frequency of the allocation made. I don't see how it could be
further optimized.
After reading the following optimized memory pool documentation:
https://github.com/cacay/MemoryPool
I just realized how obvious it is. You just add some timer to determine
the frequency, you measure the speed of the allocation requests and you
"adapt" the memory chunks you allocate that will be later subdivided
into the sizeof the type of the object. All of this type-oriented.
So if you allocate 1,000,000 integers a second then larger memory blocks
of sizeof(int) * 1000000 * CONSTANT will be allocated at once.
I am cross-posting this message with the Boost mailing list because it
is so evident.
Just to conclude I did try the attached benchmark and I get the
following on a x86_64 @ 2.40 GHz:
0: 61331143.40263957 allocations / second
1: 63644162.93924019 allocations / second
2: 177628727.5388474 allocations / second
3: 179850939.5413082 allocations / second
1 / 0: 103.7713621632905% boost
2 / 1: 101.2510431354494% boost
So the fast_pool_allocator is already pretty fast and I can only get a
1% speed boost by allocating big memory blocks. So it doesn't look like
there is any way to make the fast_pool_allocator any faster.
Regards,
-Phil
#include <limits>
#include <iomanip>
#include <boost/timer.hpp>
#include <boost/pool/pool_alloc.hpp>
using namespace std;
using namespace boost;
int main()
{
double speed[4];
static int const n = 100000000;
cout << setprecision(numeric_limits<double>::digits10 + 1);
{
pool_allocator<char, default_user_allocator_new_delete, details::pool::default_mutex> p;
timer t;
for (int i = 0; i < n; ++ i)
p.allocate(1);
speed[0] = n / t.elapsed();
}
{
pool_allocator<char, default_user_allocator_new_delete, details::pool::default_mutex, n> p;
timer t;
for (int i = 0; i < n; ++ i)
p.allocate(1);
speed[1] = n / t.elapsed();
}
{
fast_pool_allocator<char, default_user_allocator_new_delete, details::pool::default_mutex> p;
timer t;
for (int i = 0; i < n; ++ i)
p.allocate(1);
speed[2] = n / t.elapsed();
}
{
fast_pool_allocator<char, default_user_allocator_new_delete, details::pool::default_mutex, n> p;
timer t;
for (int i = 0; i < n; ++ i)
p.allocate(1);
speed[3] = n / t.elapsed();
}
for (int i = 0; i < 4; ++ i)
cout << i << ": " << speed[i] << " allocations / second" << endl;
for (int i = 0; i < 2; ++ i)
cout << i + 1 << " / " << i << ": " << speed[i * 2 + 1] / speed[i * 2] * 100 << "% boost" << endl;
return 0;
}
_______________________________________________
Development mailing list
[email protected]
http://lists.qt-project.org/mailman/listinfo/development