Boost.Pool アロケータをで使用してみましvector<wstring>
たが、通常の割り当てよりも何らかの形でパフォーマンスが向上することを期待していました (これらのvector<wstring>
ような高速な結果を期待していました)。
ただし、 Boost.Pool を使用すると、実際にはさらに悪い結果が得られているようです。たとえば、次のようになります。
15,000 回の反復の場合、
0 ms
通常の割り当てに対して が表示されますvector<wstring>
。代わりに、Boost.Pool を使用した経過時間は 5900 ミリ秒です。5,000,000回の繰り返しの場合、デフォルトのアロケーターでループを完了するのに約1300ミリ秒かかりますが、代わりに
boost::pool_allocator
多くの時間がかかります(1分後にCtrl+で中断しましたC)。
私が書いた C++ コードのベンチマークは次のとおりです。
//////////////////////////////////////////////////////////////////////////
// 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;
}
Boost.Pool を誤用していませんか? ここで何が欠けていますか?
(Boost 1.49.0 で VS2010 SP1 を使用しています)