我有以下代碼(這在很大程度上遵循第一個示例:http://www.boost.org/doc/libs/1_42_0/libs/multi_index/doc/examples.html))。出於某種原因,只有10000多插入到多索引,它需要幾分鐘來運行該程序。我做錯了什麼或這是預期的?提高緩慢插入性能的多索引
struct A
{
int id;
int name;
int age;
A(int id_,int name_,int age_):id(id_),name(name_),age(age_){}
};
/* tags for accessing the corresponding indices*/
struct id{};
struct name{};
struct age{};
typedef multi_index_container<
A,
indexed_by<
ordered_unique<
tag<id>, BOOST_MULTI_INDEX_MEMBER(A,int,id)>,
ordered_non_unique<
tag<name>,BOOST_MULTI_INDEX_MEMBER(A,int,name)>,
ordered_non_unique<
tag<age>, BOOST_MULTI_INDEX_MEMBER(A,int,age)> >
> A_set;
int main()
{
A_set es;
for (int a = 0; a != 10000; a++) {
es.insert(A(a,a+1,a+2));
}
return 0;
}
您是否設置了NDEBUG宏?如果我設置它,代碼就會很快。 – pmr 2010-07-06 11:28:53