Opened 13 years ago
Closed 13 years ago
#3518 closed Bugs (invalid)
got terible performace to use multi_index
Reported by: | Owned by: | Joaquín M López Muñoz | |
---|---|---|---|
Milestone: | Boost 1.41.0 | Component: | multi_index |
Version: | Boost 1.40.0 | Severity: | Problem |
Keywords: | Cc: |
Description
hi, first of all,multi_index is a good idea. when i test it. i got a very bad performance.
on the simplest condition,it takes 1.5 ms to 15ms to insert a element. it is too slower than many db,etc sqlite (0.031ms).
the code is listed below:
testMultiIndex2.cpp : main project file.
#include "stdafx.h"
#if !defined(NDEBUG) #define BOOST_MULTI_INDEX_ENABLE_INVARIANT_CHECKING #define BOOST_MULTI_INDEX_ENABLE_SAFE_MODE #endif
#include <boost/multi_index_container.hpp> #include <boost/multi_index/member.hpp> #include <boost/multi_index/ordered_index.hpp> #include <algorithm> #include <iostream> #include <iterator> #include <string>
#include <tchar.h> #include "..\..\..\..\..\src\common_cpp\tchar_ex.h" #include "..\..\..\..\..\src\common_cpp2\TsCommonCpp2\TsCommonCpp2\RecTime.h"
#include "..\..\..\..\..\trunk\src\common_cpp\StrDigEtc.h"
using boost::multi_index_container; using namespace boost::multi_index;
using namespace std; using namespace System; using namespace dbset;
class employee { public:
employee() {}
employee(int id_,_tstring name_,int age_):id(id_),name(name_),age(age_){}
public:
int id; _tstring name; int age;
friend _tostream& operator<<(_tostream& os,const employee& e) {
os<<e.id<<" "<<e.name<<" "<<e.age<<std::endl; return os;
}
};
struct id{}; struct name{}; struct age{};
typedef multi_index_container<
employee, indexed_by<
ordered_unique<
tag<id>, BOOST_MULTI_INDEX_MEMBER(employee,int,id)>
,
ordered_non_unique< tag<name>,BOOST_MULTI_INDEX_MEMBER(employee,_tstring,name)>, ordered_non_unique< tag<age>, BOOST_MULTI_INDEX_MEMBER(employee,int,age)>
employee_set;
template<typename Tag,typename MultiIndexContainer> void print_out_by(
const MultiIndexContainer& s, Tag* =0 /* fixes a MSVC++ 6.0 bug with implicit template function parms */
) {
/* obtain a reference to the index tagged by Tag */
const typename boost::multi_index::index<MultiIndexContainer,Tag>::type& i=
get<Tag>(s);
typedef typename MultiIndexContainer::value_type value_type;
/* dump the elements of the index to cout */
std::copy(i.begin(),i.end(),std::ostream_iterator<value_type>(std::cout));
}
int main(array<System::String ^> args) {
Console::WriteLine(L"start ...");
CRecTime rectimer;
rectimer.setStart();
employee_set es;
int max;
rectimer.setStart();
max = 10; max = 1000; max = 1000 * 10;
_tstring name;
for(int i = 0, j=max; i < max; i ++,j--) {
name = _T("Albert-"); name += StrDigEtc::itoa(i); es.insert(employee(i,name,j));
}
rectimer.setStop();
_tcout << _T("exec time is : ") << rectimer.getTimePassed() << endl; _tcout << _T("perline consume time is : ") << double(rectimer.getTimePassedNano()) / (double) max << endl;
Console::WriteLine(L"end ...");
return 0;
}
Change History (2)
comment:1 by , 13 years ago
comment:2 by , 13 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
I understand you're running your test program in debug mode. If so, invariant-checking mode and safe mode (enabled in your code by defining BOOST_MULTI_INDEX_ENABLE_INVARIANT_CHECKING and BOOST_MULTI_INDEX_ENABLE_SAFE_MODE), and in particular the former, will greatly decrease performance. These are meant to be used as debugging aids, not in production mode. Please turn them off and recheck. Also, performance should be much better in release mode, both because it is release mode after all and because you're not defining the aforementioned macros in that case.
I'm closing this ticket, please reopen if you find more to the issue than described above.
moreover, it runs on winxp sp3 , visual c++ 2008 ,boost 1.40.0 ,and cpu is amd 3600+,ram 3g