具有缓慢插入性能的多索引

tsi*_*iki 5 c++ boost

我有以下代码(主要遵循这里的第一个示例: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; 
}
Run Code Online (Sandbox Code Playgroud)

Jac*_*cob 12

您是否有机会在调试模式下编译?它使用Visual Studio 2008中的默认发布配置即刻完成.如果您正在调试模式下进行编译,并且几乎遵循示例信函,包括预处理器的内容,并且仍然有这部分:

#ifndef NDEBUG
#define BOOST_MULTI_INDEX_ENABLE_INVARIANT_CHECKING
#define BOOST_MULTI_INDEX_ENABLE_SAFE_MODE
#endif
Run Code Online (Sandbox Code Playgroud)

然后删除/禁用这些定义也将大大加快执行时间.(在我的机器上至少180x,并没有让它完成.)我不知道在调试版本中禁用或删除这些东西的后果是什么.