Changes introduced by the new intrusive version.

[SVN r39550]
This commit is contained in:
Ion Gaztañaga committed 2007-09-26 17:38:32 +00:00
1 parent cbb4812c00
commit c4aa57001c
32 files changed
+2259 -1025

No files matched your search

+58 -45
View File
@@ -11,6 +11,7 @@
/////////////////////////////////////////////////////////////////////////////
//Includes for tests
#include <boost/config.hpp>
#include <list>
#include <functional>
#include <iostream>
@@ -26,11 +27,8 @@ const int NumElements = 100000;
using namespace boost::intrusive;
template<bool BigSize>
struct filler { int dummy[10]; };
template <>
struct filler<false> {};
template<bool BigSize> struct filler { int dummy[10]; };
template <> struct filler<false> {};
template<bool BigSize> //The object for non-intrusive containers
struct test_class : private filler<BigSize>
@@ -42,8 +40,9 @@ struct test_class : private filler<BigSize>
friend bool operator >(const test_class &l, const test_class &r) { return l.i_ > r.i_; }
};
template <bool BigSize, linking_policy Policy> //The object for intrusive containers
struct itest_class : public list_base_hook<tag, Policy>, public test_class<BigSize>
template <bool BigSize, link_mode_type LinkMode>
struct itest_class //The object for intrusive containers
: public list_base_hook<link_mode<LinkMode> >, public test_class<BigSize>
{
itest_class() {}
itest_class(int i) : test_class<BigSize>(i) {}
@@ -60,11 +59,10 @@ struct func_ptr_adaptor : public FuncObj
};
//]
template <bool BigSize, linking_policy Policy>
template <bool BigSize, link_mode_type LinkMode>
struct get_ilist //Helps to define an intrusive list from a policy
{
typedef list_base_hook<tag, Policy> hook;
typedef list<typename hook::template value_traits<itest_class<BigSize, Policy> >, false> type;
typedef list<itest_class<BigSize, LinkMode>, constant_time_size<false> > type;
};
template <bool BigSize> //Helps to define an std list
@@ -73,17 +71,16 @@ struct get_list { typedef std::list<test_class<BigSize> > type; };
template <bool BigSize> //Helps to define an std pointer list
struct get_ptrlist { typedef std::list<test_class<BigSize>*> type; };
////////////////////////////////////////////////////////////////////////
//
// PUSH_BACK
//
////////////////////////////////////////////////////////////////////////
template <bool BigSize, linking_policy Policy>
template <bool BigSize, link_mode_type LinkMode>
void test_intrusive_list_push_back()
{
typedef typename get_ilist<BigSize, Policy>::type ilist;
typedef typename get_ilist<BigSize, LinkMode>::type ilist;
ptime tini = microsec_clock::universal_time();
for(int i = 0; i < NumIter; ++i){
//First create the elements and insert them in the intrusive list
@@ -93,11 +90,12 @@ void test_intrusive_list_push_back()
for(int i = 0; i < NumElements; ++i)
l.push_back(objects[i]);
//Elements are unlinked in ilist's destructor
//Elements are disposed in vector's destructor
//Elements are destroyed in vector's destructor
//]
}
ptime tend = microsec_clock::universal_time();
std::cout << "usecs/iteration: " << (tend-tini).total_microseconds()/NumIter << std::endl;
std::cout << "link_mode: " << LinkMode << ", usecs/iteration: "
<< (tend-tini).total_microseconds()/NumIter << std::endl;
}
template <bool BigSize>
@@ -111,11 +109,12 @@ void test_std_list_push_back()
stdlist l;
for(int i = 0; i < NumElements; ++i)
l.push_back(typename stdlist::value_type(i));
//Elements unlinked and disposed in stdlist's destructor
//Elements unlinked and destroyed in stdlist's destructor
//]
}
ptime tend = microsec_clock::universal_time();
std::cout << "usecs/iteration: " << (tend-tini).total_microseconds()/NumIter << std::endl;
std::cout << "std::list usecs/iteration: "
<< (tend-tini).total_microseconds()/NumIter << std::endl;
}
template <bool BigSize>
@@ -132,12 +131,13 @@ void test_compact_std_ptrlist_push_back()
stdptrlist l;
for(int i = 0; i < NumElements; ++i)
l.push_back(&objects[i]);
//Pointers to elements unlinked and disposed in stdptrlist's destructor
//Elements disposed in vector's destructor
//Pointers to elements unlinked and destroyed in stdptrlist's destructor
//Elements destroyed in vector's destructor
//]
}
ptime tend = microsec_clock::universal_time();
std::cout << "usecs/iteration: " << (tend-tini).total_microseconds()/NumIter << std::endl;
std::cout << "compact std::list usecs/iteration: "
<< (tend-tini).total_microseconds()/NumIter << std::endl;
}
template <bool BigSize>
@@ -155,12 +155,13 @@ void test_disperse_std_ptrlist_push_back()
objects.push_back(typename stdlist::value_type(i));
l.push_back(&objects.back());
}
//Pointers to elements unlinked and disposed in stdptrlist's destructor
//Elements unlinked and disposed in stdlist's destructor
//Pointers to elements unlinked and destroyed in stdptrlist's destructor
//Elements unlinked and destroyed in stdlist's destructor
//]
}
ptime tend = microsec_clock::universal_time();
std::cout << "usecs/iteration: " << (tend-tini).total_microseconds()/NumIter << std::endl;
std::cout << "disperse std::list usecs/iteration: "
<< (tend-tini).total_microseconds()/NumIter << std::endl;
}
////////////////////////////////////////////////////////////////////////
@@ -170,10 +171,10 @@ void test_disperse_std_ptrlist_push_back()
////////////////////////////////////////////////////////////////////////
//[perf_list_reverse
template <bool BigSize, linking_policy Policy>
template <bool BigSize, link_mode_type LinkMode>
void test_intrusive_list_reverse()
{
typedef typename get_ilist<BigSize, Policy>::type ilist;
typedef typename get_ilist<BigSize, LinkMode>::type ilist;
//First create the elements
std::vector<typename ilist::value_type> objects(NumElements);
@@ -186,7 +187,8 @@ void test_intrusive_list_reverse()
l.reverse();
}
ptime tend = microsec_clock::universal_time();
std::cout << "usecs/iteration: " << (tend-tini).total_microseconds()/NumIter << std::endl;
std::cout << "link_mode: " << LinkMode << ", usecs/iteration: "
<< (tend-tini).total_microseconds()/NumIter << std::endl;
}
template <bool BigSize>
@@ -205,7 +207,8 @@ void test_std_list_reverse()
l.reverse();
}
ptime tend = microsec_clock::universal_time();
std::cout << "usecs/iteration: " << (tend-tini).total_microseconds()/NumIter << std::endl;
std::cout << "std::list usecs/iteration: "
<< (tend-tini).total_microseconds()/NumIter << std::endl;
}
template <bool BigSize>
@@ -228,7 +231,8 @@ void test_compact_std_ptrlist_reverse()
l.reverse();
}
ptime tend = microsec_clock::universal_time();
std::cout << "usecs/iteration: " << (tend-tini).total_microseconds()/NumIter << std::endl;
std::cout << "compact std::list usecs/iteration: "
<< (tend-tini).total_microseconds()/NumIter << std::endl;
}
template <bool BigSize>
@@ -252,7 +256,8 @@ void test_disperse_std_ptrlist_reverse()
l.reverse();
}
ptime tend = microsec_clock::universal_time();
std::cout << "usecs/iteration: " << (tend-tini).total_microseconds()/NumIter << std::endl;
std::cout << "disperse std::list usecs/iteration: "
<< (tend-tini).total_microseconds()/NumIter << std::endl;
}
//]
@@ -263,10 +268,10 @@ void test_disperse_std_ptrlist_reverse()
////////////////////////////////////////////////////////////////////////
//[perf_list_sort
template <bool BigSize, linking_policy Policy>
template <bool BigSize, link_mode_type LinkMode>
void test_intrusive_list_sort()
{
typedef typename get_ilist<BigSize, Policy>::type ilist;
typedef typename get_ilist<BigSize, LinkMode>::type ilist;
//First create the elements
std::vector<typename ilist::value_type> objects(NumElements);
@@ -287,7 +292,8 @@ void test_intrusive_list_sort()
}
}
ptime tend = microsec_clock::universal_time();
std::cout << "usecs/iteration: " << (tend-tini).total_microseconds()/NumIter << std::endl;
std::cout << "link_mode: " << LinkMode << ", usecs/iteration: "
<< (tend-tini).total_microseconds()/NumIter << std::endl;
}
template <bool BigSize>
@@ -311,7 +317,8 @@ void test_std_list_sort()
}
}
ptime tend = microsec_clock::universal_time();
std::cout << "usecs/iteration: " << (tend-tini).total_microseconds()/NumIter << std::endl;
std::cout << "std::list usecs/iteration: "
<< (tend-tini).total_microseconds()/NumIter << std::endl;
}
template <bool BigSize>
@@ -340,7 +347,8 @@ void test_compact_std_ptrlist_sort()
}
}
ptime tend = microsec_clock::universal_time();
std::cout << "usecs/iteration: " << (tend-tini).total_microseconds()/NumIter << std::endl;
std::cout << "compact std::list usecs/iteration: "
<< (tend-tini).total_microseconds()/NumIter << std::endl;
}
template <bool BigSize>
@@ -368,7 +376,8 @@ void test_disperse_std_ptrlist_sort()
}
}
ptime tend = microsec_clock::universal_time();
std::cout << "usecs/iteration: " << (tend-tini).total_microseconds()/NumIter << std::endl;
std::cout << "disperse std::list usecs/iteration: "
<< (tend-tini).total_microseconds()/NumIter << std::endl;
}
//]
@@ -378,10 +387,10 @@ void test_disperse_std_ptrlist_sort()
//
////////////////////////////////////////////////////////////////////////
//[perf_list_write_access
template <bool BigSize, linking_policy Policy>
template <bool BigSize, link_mode_type LinkMode>
void test_intrusive_list_write_access()
{
typedef typename get_ilist<BigSize, Policy>::type ilist;
typedef typename get_ilist<BigSize, LinkMode>::type ilist;
//First create the elements
std::vector<typename ilist::value_type> objects(NumElements);
@@ -401,7 +410,8 @@ void test_intrusive_list_write_access()
}
}
ptime tend = microsec_clock::universal_time();
std::cout << "usecs/iteration: " << (tend-tini).total_microseconds()/NumIter << std::endl;
std::cout << "link_mode: " << LinkMode << ", usecs/iteration: "
<< (tend-tini).total_microseconds()/NumIter << std::endl;
}
template <bool BigSize>
@@ -423,7 +433,8 @@ void test_std_list_write_access()
}
}
ptime tend = microsec_clock::universal_time();
std::cout << "usecs/iteration: " << (tend-tini).total_microseconds()/NumIter << std::endl;
std::cout << "std::list usecs/iteration: "
<< (tend-tini).total_microseconds()/NumIter << std::endl;
}
template <bool BigSize>
@@ -452,7 +463,8 @@ void test_compact_std_ptrlist_write_access()
}
}
ptime tend = microsec_clock::universal_time();
std::cout << "usecs/iteration: " << (tend-tini).total_microseconds()/NumIter << std::endl;
std::cout << "compact std::list usecs/iteration: "
<< (tend-tini).total_microseconds()/NumIter << std::endl;
}
template <bool BigSize>
@@ -479,7 +491,8 @@ void test_disperse_std_ptrlist_write_access()
}
}
ptime tend = microsec_clock::universal_time();
std::cout << "usecs/iteration: " << (tend-tini).total_microseconds()/NumIter << std::endl;
std::cout << "disperse std::list usecs/iteration: "
<< (tend-tini).total_microseconds()/NumIter << std::endl;
}
//]
@@ -491,7 +504,7 @@ void test_disperse_std_ptrlist_write_access()
template<bool BigSize>
void do_all_tests()
{
std::cout << "Testing push back() with BigSize:" << BigSize << std::endl;
std::cout << "\n\nTesting push back() with BigSize:" << BigSize << std::endl;
test_intrusive_list_push_back<BigSize, normal_link>();
test_intrusive_list_push_back<BigSize, safe_link>();
test_intrusive_list_push_back<BigSize, auto_unlink>();
@@ -499,7 +512,7 @@ void do_all_tests()
test_compact_std_ptrlist_push_back<BigSize>();
test_disperse_std_ptrlist_push_back<BigSize>();
//reverse
std::cout << "Testing reverse() with BigSize:" << BigSize << std::endl;
std::cout << "\n\nTesting reverse() with BigSize:" << BigSize << std::endl;
test_intrusive_list_reverse<BigSize, normal_link>();
test_intrusive_list_reverse<BigSize, safe_link>();
test_intrusive_list_reverse<BigSize, auto_unlink>();
@@ -507,7 +520,7 @@ void do_all_tests()
test_compact_std_ptrlist_reverse<BigSize>();
test_disperse_std_ptrlist_reverse<BigSize>();
//sort
std::cout << "Testing sort() with BigSize:" << BigSize << std::endl;
std::cout << "\n\nTesting sort() with BigSize:" << BigSize << std::endl;
test_intrusive_list_sort<BigSize, normal_link>();
test_intrusive_list_sort<BigSize, safe_link>();
test_intrusive_list_sort<BigSize, auto_unlink>();
@@ -515,7 +528,7 @@ void do_all_tests()
test_compact_std_ptrlist_sort<BigSize>();
test_disperse_std_ptrlist_sort<BigSize>();
//write_access
std::cout << "Testing write_access() with BigSize:" << BigSize << std::endl;
std::cout << "\n\nTesting write_access() with BigSize:" << BigSize << std::endl;
test_intrusive_list_write_access<BigSize, normal_link>();
test_intrusive_list_write_access<BigSize, safe_link>();
test_intrusive_list_write_access<BigSize, auto_unlink>();