Example #1
0
void	MultiIndex::testFunction()
{
	std::vector<__int64>	kTick;
	const int iLimit( 1000000 );
	MultiIndexContainer kMultiIndexContainer;
	volatile const __int64 d1( ::GetTickCount() );
	kTick.push_back( ::GetTickCount() );
	for( int i( 0 ); i < iLimit; ++i ) {
		kMultiIndexContainer.insert( MultiIndex( boost::lexical_cast<std::string>( i ), i, i * 10 ) );

		volatile int tmp( 0 );
		++tmp;
	}
	volatile const __int64 d2( ::GetTickCount() );
	kTick.push_back( ::GetTickCount() );
	{
		MultiIndexContainer::nth_index<1>::type& IndexString = kMultiIndexContainer.get<1>();
		for( auto pos( IndexString.cbegin() ); pos != IndexString.cend(); ++pos ) {
			volatile const std::string kString( pos->getString() );
			volatile const int iID( pos->getID() );
			volatile const int iGrade( pos->getGrade() );

			volatile int tmp( 0 );
			++tmp;
		}
	}
	volatile const __int64 d3( ::GetTickCount() );
	kTick.push_back( ::GetTickCount() );
	{
		MultiIndexContainer::nth_index<1>::type& IndexString = kMultiIndexContainer.get<1>();
		const auto it( IndexString.find( boost::lexical_cast<std::string>( 100 ) ) );
		volatile const std::string kString( it->getString() );
		volatile const int iID( it->getID() );
		volatile const int iGrade( it->getGrade() );

		volatile int tmp( 0 );
		++tmp;
	}
	volatile const __int64 d4( ::GetTickCount() );
	kTick.push_back( ::GetTickCount() );
	{
		for( int i( 0 ); i < 10; ++i ) {
			kMultiIndexContainer.insert( MultiIndex( boost::lexical_cast<std::string>( i ), i, i * 10 ) );
		}
	}
	volatile const __int64 d5( ::GetTickCount() );
	kTick.push_back( ::GetTickCount() );

	volatile const __int64 t1( kTick.at( 1 ) - kTick.at( 0 ) );
	volatile const __int64 t2( kTick.at( 2 ) - kTick.at( 1 ) );
	volatile const __int64 t3( kTick.at( 3 ) - kTick.at( 2 ) );
	volatile const __int64 t4( kTick.at( 4 ) - kTick.at( 3 ) );

	volatile int tmp( 0 );
	++tmp;

	tmp = 1;

	__noop;
}
Example #2
0
void test_stable_update()
{
  typedef typename MultiIndexContainer::iterator  iterator;
  typedef typename MultiIndexContainer::size_type size_type;

  MultiIndexContainer c;
  c.insert(0);
  c.insert(1);c.insert(1);
  c.insert(2);c.insert(2);c.insert(2);c.insert(2);
  c.insert(3);
  c.insert(4);c.insert(4);c.insert(4);
  c.insert(5);c.insert(5);
  c.insert(6);
  c.insert(7);
  size_type num_elems=
    c.count(0)+c.count(1)+c.count(2)+c.count(3)+
    c.count(4)+c.count(5)+c.count(6)+c.count(7);

  for(size_type n=c.size();n--;){
    iterator it=boost::next(c.begin(),n);

    c.replace(it,*it);
    BOOST_TEST((size_type)std::distance(c.begin(),it)==n);

    c.modify(it,do_nothing());
    BOOST_TEST((size_type)std::distance(c.begin(),it)==n);

    c.modify(it,do_nothing(),do_nothing());
    BOOST_TEST((size_type)std::distance(c.begin(),it)==n);

    for(int i=0;i<=8;++i){
      MultiIndexContainer cpy(c);
      bool b=c.modify(it,assign_value(i),assign_value(*it));
      BOOST_TEST(b||(size_type)std::distance(c.begin(),it)==n);
      BOOST_TEST(c.count(0)+c.count(1)+c.count(2)+c.count(3)+c.count(4)+
                  c.count(5)+c.count(6)+c.count(7)+c.count(8)==num_elems);
      if(b){
        c=cpy;
        it=boost::next(c.begin(),n);
      }
    }
  }
}