[Boost-bugs] [Boost C++ Libraries] #3518: got terible performace to use multi_index

Subject: [Boost-bugs] [Boost C++ Libraries] #3518: got terible performace to use multi_index
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2009-10-10 03:15:44


#3518: got terible performace to use multi_index
-------------------------------------------------+--------------------------
 Reporter: david.joe <zhouyong_ts@…> | Owner: joaquin
     Type: Bugs | Status: new
Milestone: Boost 1.41.0 | Component: multi_index
  Version: Boost 1.40.0 | Severity: Problem
 Keywords: |
-------------------------------------------------+--------------------------
 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;
 }

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/3518>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:01 UTC