我尝试使用Boost.Pool分配器与vector<wstring>
,希望在通常分配某种形式的性能增益的vector<wstring>
(I期待某种快速的结果等这些 )。
然而,似乎与Boost.Pool我确实越来越差的结果,例如:
为15000次迭代计数,
0 ms
被显示为通常分配vector<wstring>
,而不是使用Boost.Pool是5900毫秒的经过时间;为5,000,000迭代计数大约需要1300毫秒完成与默认分配器的循环,而不是用
boost::pool_allocator
需要花费大量的时间(一分钟我用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? 我缺少的是在这里吗?
(我使用的是升压1.49.0 VS2010 SP1)