Using the <wstring> vector with Boost.Pool allocator

I tried using the Boost.Pool allocator with vector<wstring> , expecting some form of performance increase over the usually allocated vector<wstring> (I was expecting some kind of quick results like these ).

However, it looks like with Boost.Pool I really get worse results, for example:

  • to count 15,000 iterations, 0 ms displayed for the usually selected vector<wstring> , instead, the elapsed time using Boost.Pool is 5900 ms;

  • counting 5,000,000 iterations takes about 1300 ms to complete the loop using the default allocator, instead it takes a lot of time with boost::pool_allocator (after a minute I broke down with Ctrl + C ).

Here is the C ++ code benchmark that I wrote:

 ////////////////////////////////////////////////////////////////////////// // TestBoostPool.cpp // Testing vector<wstring> with Boost.Pool ////////////////////////////////////////////////////////////////////////// #include <exception> #include <iostream> #include <stdexcept> #include <string> #include <vector> // To avoid linking with Boost Thread library #define BOOST_DISABLE_THREADS #include <boost/pool/pool_alloc.hpp> #include <boost/timer/timer.hpp> using namespace std; void Test() { // Loop iteration count static const int count = 5*1000*1000; // // Testing ordinary vector<wstring> // cout << "Testing vector<wstring>" << endl; { boost::timer::auto_cpu_timer t; vector<wstring> vec; for (int i = 0; i < count; i++) { wstring s(L"I think therefore I am; just a simple test string."); vec.push_back(s); } } // // Testing vector<wstring> with Boost.Pool // cout << "Testing vector<wstring> with Boost.Pool" << endl; { boost::timer::auto_cpu_timer t; typedef basic_string<wchar_t, char_traits<wchar_t>, boost::fast_pool_allocator<wchar_t>> PoolString; vector<PoolString> vec; for (int i = 0; i < count; i++) { PoolString s(L"I think therefore I am; just a simple test string."); vec.push_back(s); } // Release pool memory boost::singleton_pool<boost::fast_pool_allocator_tag, sizeof(wchar_t)>::release_memory(); } cout << endl; } int main() { const int exitOk = 0; const int exitError = 1; try { Test(); } catch(const exception & e) { cerr << "\n*** ERROR: " << e.what() << endl; return exitError; } return exitOk; } 

Am I abusing Boost.Pool? What am I missing here?

(I am using VS2010 SP1 with Boost 1.49.0)

+3
source share
1 answer

FYI Boost.Pool is not designed for this or optimized for this use - it is designed for a large number of blocks of a fixed size, as happens in a list (or even a map or set), it is not intended for quick work with blocks with a variable size, like this occurs in a line or vector.

+11
source

Source: https://habr.com/ru/post/1410866/


All Articles