Boost logo

Boost :

Subject: Re: [boost] Boost MultiIndex slow mass insertion
From: Richard Hodges (hodges.r_at_[hidden])
Date: 2017-04-28 15:49:47


Some thoughts:

1. How big and complex is a MyClass? You're inserting a copy. Could that be
the source of the overhead?

2. The performance of a sort of N items is no better than an ordered insert
of N items. If MyClass does not have move operators, and is large,
performance of the sort will be worse.

On 27 April 2017 at 11:38, miticodonati--- via Boost <boost_at_[hidden]>
wrote:

> I have the following structure:
>
> typedef boost::multi_index_container<
> MyClass,
> boost::multi_index::indexed_by<
> boost::multi_index::hashed_unique<boost::multi_index::member<MyClass,
> int, &amp;MyClass::label>>,
> boost::multi_index::ordered_non_unique<boost::multi_index::member<MyClass,
> double, &amp;MyClass::dist>>
> >
> > MyClassSet;
>
> If i populate it in a loop:
>
> MyClassSet all:
> for (int y = 0; y < input.rows; ++y) {
> MyClass c;
> // ....
> all.insert(c);
> }
>
> the insertion time is quite slow. It probably need to continuously
> re-order the underlying implementation.
> Anyway i would expect that populating it with a single call it would be
> faster (e.g. sorting the whole set only at the end).
> Example:
>
> std::vector<MyClass> vec;
> // ...
> MyClassSet all(vec.begin(), vec.end());
>
> BUT... the times are almost equal.
>
> My question is: is this intended behaviour?
> Is there a faster way to mass populate the container (e.g. not enforcing
> the invariants/orderings at each 'insert')?
>
>
>
> _______________________________________________
> Unsubscribe & other changes: http://lists.boost.org/
> mailman/listinfo.cgi/boost
>


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk