From: khizmax Date: Sun, 13 Sep 2015 13:58:11 +0000 (+0300) Subject: Refactored Set_InsDelFind MT-test X-Git-Tag: v2.1.0~120 X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=7eb02112b5e9761ac5b13f35c9ccea9e39f98a70;hp=d0eb9e0849eac0d1e7fba6b245a5e065ceb814bb;p=libcds.git Refactored Set_InsDelFind MT-test --- diff --git a/projects/Win/vc12/unit-prerequisites.vcxproj b/projects/Win/vc12/unit-prerequisites.vcxproj index 7c1bc845..d0c00115 100644 --- a/projects/Win/vc12/unit-prerequisites.vcxproj +++ b/projects/Win/vc12/unit-prerequisites.vcxproj @@ -425,7 +425,18 @@ - + + Level2 + Level2 + Level2 + Level2 + Level2 + Level2 + Level2 + Level2 + Level2 + Level2 + diff --git a/projects/Win/vc12/unit-set-insdelfind.vcxproj b/projects/Win/vc12/unit-set-insdelfind.vcxproj index b2685377..1bcaba07 100644 --- a/projects/Win/vc12/unit-set-insdelfind.vcxproj +++ b/projects/Win/vc12/unit-set-insdelfind.vcxproj @@ -47,7 +47,7 @@ - + diff --git a/projects/source.unit.set.mk b/projects/source.unit.set.mk index abbdd95d..ee11421e 100644 --- a/projects/source.unit.set.mk +++ b/projects/source.unit.set.mk @@ -18,10 +18,10 @@ CDSUNIT_SET_SOURCES := \ tests/unit/set2/set_insdel_string_striped.cpp \ tests/unit/set2/set_insdel_string_std.cpp \ tests/unit/set2/set_insdelfind.cpp \ - tests/unit/set2/set_insdelfind_michael.cpp \ tests/unit/set2/set_insdelfind_cuckoo.cpp \ tests/unit/set2/set_insdelfind_ellentree.cpp \ - tests/unit/set2/set_insdelfind_refinable.cpp \ + tests/unit/set2/set_insdelfind_michael.cpp \ + tests/unit/set2/set_insdelfind_multilevelhashset.cpp \ tests/unit/set2/set_insdelfind_skip.cpp \ tests/unit/set2/set_insdelfind_split.cpp \ tests/unit/set2/set_insdelfind_striped.cpp \ diff --git a/tests/unit/set2/CMakeLists.txt b/tests/unit/set2/CMakeLists.txt index 408b5f79..15d99ae3 100644 --- a/tests/unit/set2/CMakeLists.txt +++ b/tests/unit/set2/CMakeLists.txt @@ -19,10 +19,10 @@ set(CDSUNIT_SET_SOURCES set_insdel_string_striped.cpp set_insdel_string_std.cpp set_insdelfind.cpp - set_insdelfind_michael.cpp set_insdelfind_cuckoo.cpp set_insdelfind_ellentree.cpp - set_insdelfind_refinable.cpp + set_insdelfind_michael.cpp + set_insdelfind_multilevelhashset.cpp set_insdelfind_skip.cpp set_insdelfind_split.cpp set_insdelfind_striped.cpp diff --git a/tests/unit/set2/set_insdelfind.cpp b/tests/unit/set2/set_insdelfind.cpp index 56df57c7..3330b278 100644 --- a/tests/unit/set2/set_insdelfind.cpp +++ b/tests/unit/set2/set_insdelfind.cpp @@ -5,17 +5,9 @@ namespace set2 { CPPUNIT_TEST_SUITE_REGISTRATION( Set_InsDelFind ); - size_t Set_InsDelFind::c_nInitialMapSize = 500000; - size_t Set_InsDelFind::c_nThreadCount = 8; - size_t Set_InsDelFind::c_nMaxLoadFactor = 8; - unsigned int Set_InsDelFind::c_nInsertPercentage = 5; - unsigned int Set_InsDelFind::c_nDeletePercentage = 5; - unsigned int Set_InsDelFind::c_nDuration = 30; - bool Set_InsDelFind::c_bPrintGCState = true; - void Set_InsDelFind::setUpParams( const CppUnitMini::TestCfg& cfg ) { - c_nInitialMapSize = cfg.getSizeT("InitialMapSize", c_nInitialMapSize ); + c_nSetSize = cfg.getSizeT("InitialMapSize", c_nSetSize ); c_nThreadCount = cfg.getSizeT("ThreadCount", c_nThreadCount ); c_nMaxLoadFactor = cfg.getSizeT("MaxLoadFactor", c_nMaxLoadFactor ); c_nInsertPercentage = cfg.getUInt("InsertPercentage", c_nInsertPercentage ); @@ -23,8 +15,12 @@ namespace set2 { c_nDuration = cfg.getUInt("Duration", c_nDuration ); c_bPrintGCState = cfg.getBool("PrintGCStateFlag", c_bPrintGCState ); + c_nCuckooInitialSize = cfg.getSizeT("CuckooInitialSize", c_nCuckooInitialSize ); + c_nCuckooProbesetSize = cfg.getSizeT("CuckooProbesetSize", c_nCuckooProbesetSize ); + c_nCuckooProbesetThreshold = cfg.getSizeT("CuckooProbesetThreshold", c_nCuckooProbesetThreshold ); + if ( c_nThreadCount == 0 ) - c_nThreadCount = cds::OS::topology::processor_count() * 2; + c_nThreadCount = std::thread::hardware_concurrency(); CPPUNIT_ASSERT( c_nInsertPercentage + c_nDeletePercentage <= 100 ); @@ -39,20 +35,4 @@ namespace set2 { std::fill( pFirst, pLast, do_find ); shuffle( m_arrShuffle, pLast ); } - - void Set_InsDelFind::myRun(const char *in_name, bool invert /*= false*/) - { - setUpParams( m_Cfg.get( "Map_InsDelFind" )); - - run_MichaelSet(in_name, invert); - run_SplitList(in_name, invert); - run_SkipListSet(in_name, invert); - run_EllenBinTreeSet(in_name, invert); - run_StripedSet(in_name, invert); - run_RefinableSet(in_name, invert); - run_CuckooSet(in_name, invert); - run_StdSet(in_name, invert); - - endTestCase(); - } } // namespace set2 diff --git a/tests/unit/set2/set_insdelfind.h b/tests/unit/set2/set_insdelfind.h index bee344df..97f54de8 100644 --- a/tests/unit/set2/set_insdelfind.h +++ b/tests/unit/set2/set_insdelfind.h @@ -5,20 +5,24 @@ namespace set2 { -# define TEST_SET(IMPL, C, X) void C::X() { test::X >() ; } -# define TEST_SET_EXTRACT(IMPL, C, X) TEST_SET(IMPL, C, X) -# define TEST_SET_NOLF(IMPL, C, X) void C::X() { test_nolf::X >() ; } -# define TEST_SET_NOLF_EXTRACT(IMPL, C, X) TEST_SET_NOLF(IMPL, C, X) +#define TEST_CASE(TAG, X) void X(); class Set_InsDelFind: public CppUnitMini::TestCase { - static size_t c_nInitialMapSize; // initial map size - static size_t c_nThreadCount; // thread count - static size_t c_nMaxLoadFactor; // maximum load factor - static unsigned int c_nInsertPercentage; - static unsigned int c_nDeletePercentage; - static unsigned int c_nDuration; // test duration, seconds - static bool c_bPrintGCState; + public: + size_t c_nSetSize = 500000; // initial set size + size_t c_nThreadCount = 8; // thread count + size_t c_nMaxLoadFactor = 8; // maximum load factor + unsigned int c_nInsertPercentage = 5; + unsigned int c_nDeletePercentage = 5; + unsigned int c_nDuration = 30; // test duration, seconds + bool c_bPrintGCState = true; + + size_t c_nCuckooInitialSize = 1024;// initial size for CuckooSet + size_t c_nCuckooProbesetSize = 16; // CuckooSet probeset size (only for list-based probeset) + size_t c_nCuckooProbesetThreshold = 0; // CUckooSet probeset threshold (0 - use default) + + size_t c_nLoadFactor = 2; public: enum actions @@ -83,7 +87,7 @@ namespace set2 { actions * pAct = getTest().m_arrShuffle; unsigned int i = 0; - size_t const nNormalize = size_t(-1) / (c_nInitialMapSize * 2); + size_t const nNormalize = size_t(-1) / ( getTest().c_nSetSize * 2); size_t nRand = 0; while ( !time_elapsed() ) { @@ -91,7 +95,7 @@ namespace set2 { size_t n = nRand / nNormalize; switch ( pAct[i] ) { case do_find: - if ( rMap.find( n )) + if ( rMap.contains( n )) ++m_nFindSuccess; else ++m_nFindFailed; @@ -118,24 +122,15 @@ namespace set2 { protected: template - void do_test( size_t nLoadFactor ) - { - CPPUNIT_MSG( "Load factor=" << nLoadFactor ); - - Set testSet( c_nInitialMapSize, nLoadFactor ); - do_test_with( testSet ); - } - - template - void do_test_with( Set& testSet ) + void do_test( Set& testSet ) { typedef WorkThread work_thread; // fill map - only odd number { - size_t * pInitArr = new size_t[ c_nInitialMapSize ]; - size_t * pEnd = pInitArr + c_nInitialMapSize; - for ( size_t i = 0; i < c_nInitialMapSize; ++i ) + size_t * pInitArr = new size_t[ c_nSetSize ]; + size_t * pEnd = pInitArr + c_nSetSize; + for ( size_t i = 0; i < c_nSetSize; ++i ) pInitArr[i] = i * 2 + 1; shuffle( pInitArr, pEnd ); for ( size_t * p = pInitArr; p < pEnd; ++p ) @@ -193,52 +188,34 @@ namespace set2 { } template - void test() + void run_test() { CPPUNIT_MSG( "Thread count=" << c_nThreadCount - << " initial map size=" << c_nInitialMapSize + << " initial map size=" << c_nSetSize << " insert=" << c_nInsertPercentage << '%' << " delete=" << c_nDeletePercentage << '%' << " duration=" << c_nDuration << "s" ); - for ( size_t nLoadFactor = 1; nLoadFactor <= c_nMaxLoadFactor; nLoadFactor *= 2 ) { - do_test( nLoadFactor ); + if ( Set::c_bLoadFactorDepended ) { + for ( c_nLoadFactor = 1; c_nLoadFactor <= c_nMaxLoadFactor; c_nLoadFactor *= 2 ) { + CPPUNIT_MSG(" LoadFactor = " << c_nLoadFactor ); + Set s( *this ); + do_test( s ); + if ( c_bPrintGCState ) + print_gc_state(); + } + } + else { + Set s( *this ); + do_test( s ); if ( c_bPrintGCState ) print_gc_state(); } } - template - void test_nolf() - { - CPPUNIT_MSG( "Thread count=" << c_nThreadCount - << " initial map size=" << c_nInitialMapSize - << " insert=" << c_nInsertPercentage << '%' - << " delete=" << c_nDeletePercentage << '%' - << " duration=" << c_nDuration << "s" - ); - - Set s; - do_test_with( s ); - //CPPUNIT_MSG( s.statistics() ); - if ( c_bPrintGCState ) - print_gc_state(); - } - void setUpParams( const CppUnitMini::TestCfg& cfg ); - void run_MichaelSet(const char *in_name, bool invert = false); - void run_SplitList(const char *in_name, bool invert = false); - void run_SkipListSet(const char *in_name, bool invert = false); - void run_CuckooSet(const char *in_name, bool invert = false); - void run_StripedSet(const char *in_name, bool invert = false); - void run_RefinableSet(const char *in_name, bool invert = false); - void run_EllenBinTreeSet(const char *in_name, bool invert = false); - void run_StdSet(const char *in_name, bool invert = false); - - virtual void myRun(const char *in_name, bool invert = false); - # include "set2/set_defs.h" CDSUNIT_DECLARE_MichaelSet CDSUNIT_DECLARE_SplitList @@ -247,6 +224,20 @@ namespace set2 { CDSUNIT_DECLARE_CuckooSet CDSUNIT_DECLARE_SkipListSet CDSUNIT_DECLARE_EllenBinTreeSet + CDSUNIT_DECLARE_MultiLevelHashSet CDSUNIT_DECLARE_StdSet + + CPPUNIT_TEST_SUITE_(Set_InsDelFind, "Map_InsDelFind") + CDSUNIT_TEST_MichaelSet + CDSUNIT_TEST_SplitList + CDSUNIT_TEST_SkipListSet + CDSUNIT_TEST_MultiLevelHashSet + CDSUNIT_TEST_EllenBinTreeSet + CDSUNIT_TEST_StripedSet + CDSUNIT_TEST_RefinableSet + CDSUNIT_TEST_CuckooSet + CDSUNIT_TEST_StdSet + CPPUNIT_TEST_SUITE_END(); + }; } // namespace set2 diff --git a/tests/unit/set2/set_insdelfind_cuckoo.cpp b/tests/unit/set2/set_insdelfind_cuckoo.cpp index fee46ea3..48069d26 100644 --- a/tests/unit/set2/set_insdelfind_cuckoo.cpp +++ b/tests/unit/set2/set_insdelfind_cuckoo.cpp @@ -3,10 +3,10 @@ #include "set2/set_insdelfind.h" #include "set2/set_type_cuckoo.h" -namespace set2 { - CDSUNIT_DEFINE_CuckooSet( cc::cuckoo::implementation_tag, Set_InsDelFind ) +#undef TEST_CASE +#define TEST_CASE(TAG, X) void Set_InsDelFind::X() { run_test::X>(); } +#include "set2/set_defs.h" - CPPUNIT_TEST_SUITE_PART( Set_InsDelFind, run_CuckooSet ) - CDSUNIT_TEST_CuckooSet - CPPUNIT_TEST_SUITE_END_PART() +namespace set2 { + CDSUNIT_DECLARE_CuckooSet } // namespace set2 diff --git a/tests/unit/set2/set_insdelfind_ellentree.cpp b/tests/unit/set2/set_insdelfind_ellentree.cpp index 55012370..89cb2d96 100644 --- a/tests/unit/set2/set_insdelfind_ellentree.cpp +++ b/tests/unit/set2/set_insdelfind_ellentree.cpp @@ -3,10 +3,10 @@ #include "set2/set_insdelfind.h" #include "set2/set_type_ellen_bintree.h" -namespace set2 { - CDSUNIT_DEFINE_EllenBinTreeSet( cc::ellen_bintree::implementation_tag, Set_InsDelFind ) +#undef TEST_CASE +#define TEST_CASE(TAG, X) void Set_InsDelFind::X() { run_test::X>(); } +#include "set2/set_defs.h" - CPPUNIT_TEST_SUITE_PART( Set_InsDelFind, run_EllenBinTreeSet ) - CDSUNIT_TEST_EllenBinTreeSet - CPPUNIT_TEST_SUITE_END_PART() +namespace set2 { + CDSUNIT_DECLARE_EllenBinTreeSet } // namespace set2 diff --git a/tests/unit/set2/set_insdelfind_michael.cpp b/tests/unit/set2/set_insdelfind_michael.cpp index dc4ca564..225933b8 100644 --- a/tests/unit/set2/set_insdelfind_michael.cpp +++ b/tests/unit/set2/set_insdelfind_michael.cpp @@ -3,11 +3,10 @@ #include "set2/set_insdelfind.h" #include "set2/set_type_michael.h" +#undef TEST_CASE +#define TEST_CASE(TAG, X) void Set_InsDelFind::X() { run_test::X>(); } +#include "set2/set_defs.h" namespace set2 { - CDSUNIT_DEFINE_MichaelSet( cc::michael_set::implementation_tag, Set_InsDelFind ) - - CPPUNIT_TEST_SUITE_PART( Set_InsDelFind, run_MichaelSet ) - CDSUNIT_TEST_MichaelSet - CPPUNIT_TEST_SUITE_END_PART() + CDSUNIT_DECLARE_MichaelSet } // namespace set2 diff --git a/tests/unit/set2/set_insdelfind_multilevelhashset.cpp b/tests/unit/set2/set_insdelfind_multilevelhashset.cpp new file mode 100644 index 00000000..0a374821 --- /dev/null +++ b/tests/unit/set2/set_insdelfind_multilevelhashset.cpp @@ -0,0 +1,12 @@ +//$$CDS-header$$ + +#include "set2/set_insdelfind.h" +#include "set2/set_type_multilevel_hashset.h" + +#undef TEST_CASE +#define TEST_CASE(TAG, X) void Set_InsDelFind::X() { run_test::X>(); } +#include "set2/set_defs.h" + +namespace set2 { + CDSUNIT_DECLARE_MultiLevelHashSet +} // namespace set2 diff --git a/tests/unit/set2/set_insdelfind_refinable.cpp b/tests/unit/set2/set_insdelfind_refinable.cpp deleted file mode 100644 index ac969d47..00000000 --- a/tests/unit/set2/set_insdelfind_refinable.cpp +++ /dev/null @@ -1,12 +0,0 @@ -//$$CDS-header$$ - -#include "set2/set_insdelfind.h" -#include "set2/set_type_striped.h" - -namespace set2 { - CDSUNIT_DEFINE_RefinableSet( cc::striped_set::implementation_tag, Set_InsDelFind ) - - CPPUNIT_TEST_SUITE_PART( Set_InsDelFind, run_RefinableSet ) - CDSUNIT_TEST_RefinableSet - CPPUNIT_TEST_SUITE_END_PART() -} // namespace set2 diff --git a/tests/unit/set2/set_insdelfind_skip.cpp b/tests/unit/set2/set_insdelfind_skip.cpp index 102c51d3..0883424b 100644 --- a/tests/unit/set2/set_insdelfind_skip.cpp +++ b/tests/unit/set2/set_insdelfind_skip.cpp @@ -3,10 +3,10 @@ #include "set2/set_insdelfind.h" #include "set2/set_type_skip_list.h" -namespace set2 { - CDSUNIT_DEFINE_SkipListSet(cc::skip_list::implementation_tag, Set_InsDelFind) +#undef TEST_CASE +#define TEST_CASE(TAG, X) void Set_InsDelFind::X() { run_test::X>(); } +#include "set2/set_defs.h" - CPPUNIT_TEST_SUITE_PART( Set_InsDelFind, run_SkipListSet ) - CDSUNIT_TEST_SkipListSet - CPPUNIT_TEST_SUITE_END_PART() +namespace set2 { + CDSUNIT_DECLARE_SkipListSet } // namespace set2 diff --git a/tests/unit/set2/set_insdelfind_split.cpp b/tests/unit/set2/set_insdelfind_split.cpp index 4c393df3..f6c602db 100644 --- a/tests/unit/set2/set_insdelfind_split.cpp +++ b/tests/unit/set2/set_insdelfind_split.cpp @@ -3,10 +3,10 @@ #include "set2/set_insdelfind.h" #include "set2/set_type_split_list.h" -namespace set2 { - CDSUNIT_DEFINE_SplitList(cc::split_list::implementation_tag, Set_InsDelFind) +#undef TEST_CASE +#define TEST_CASE(TAG, X) void Set_InsDelFind::X() { run_test::X>(); } +#include "set2/set_defs.h" - CPPUNIT_TEST_SUITE_PART( Set_InsDelFind, run_SplitList ) - CDSUNIT_TEST_SplitList - CPPUNIT_TEST_SUITE_END_PART() +namespace set2 { + CDSUNIT_DECLARE_SplitList } // namespace set2 diff --git a/tests/unit/set2/set_insdelfind_std.cpp b/tests/unit/set2/set_insdelfind_std.cpp index d5e999d9..548f16cd 100644 --- a/tests/unit/set2/set_insdelfind_std.cpp +++ b/tests/unit/set2/set_insdelfind_std.cpp @@ -3,10 +3,10 @@ #include "set2/set_insdelfind.h" #include "set2/set_type_std.h" -namespace set2 { - CDSUNIT_DEFINE_StdSet(std_implementation_tag, Set_InsDelFind) +#undef TEST_CASE +#define TEST_CASE(TAG, X) void Set_InsDelFind::X() { run_test::X>(); } +#include "set2/set_defs.h" - CPPUNIT_TEST_SUITE_PART( Set_InsDelFind, run_StdSet ) - CDSUNIT_TEST_StdSet - CPPUNIT_TEST_SUITE_END_PART() +namespace set2 { + CDSUNIT_DECLARE_StdSet } // namespace set2 diff --git a/tests/unit/set2/set_insdelfind_striped.cpp b/tests/unit/set2/set_insdelfind_striped.cpp index 15bb7888..d4de9674 100644 --- a/tests/unit/set2/set_insdelfind_striped.cpp +++ b/tests/unit/set2/set_insdelfind_striped.cpp @@ -3,10 +3,11 @@ #include "set2/set_insdelfind.h" #include "set2/set_type_striped.h" -namespace set2 { - CDSUNIT_DEFINE_StripedSet( cc::striped_set::implementation_tag, Set_InsDelFind ) +#undef TEST_CASE +#define TEST_CASE(TAG, X) void Set_InsDelFind::X() { run_test::X>(); } +#include "set2/set_defs.h" - CPPUNIT_TEST_SUITE_PART( Set_InsDelFind, run_StripedSet ) - CDSUNIT_TEST_StripedSet - CPPUNIT_TEST_SUITE_END_PART() +namespace set2 { + CDSUNIT_DECLARE_StripedSet + CDSUNIT_DECLARE_RefinableSet } // namespace set2 diff --git a/tests/unit/set2/set_type_multilevel_hashset.h b/tests/unit/set2/set_type_multilevel_hashset.h index c13d1fc4..45b3bcc3 100644 --- a/tests/unit/set2/set_type_multilevel_hashset.h +++ b/tests/unit/set2/set_type_multilevel_hashset.h @@ -42,6 +42,12 @@ namespace set2 { return base_class::extract( hasher()(key) ); } + template + bool contains( Q const& key ) + { + return base_class::contains( hasher()(key) ); + } + // for testing static CDS_CONSTEXPR bool const c_bExtractSupported = true; static CDS_CONSTEXPR bool const c_bLoadFactorDepended = false; diff --git a/tests/unit/set2/set_type_std.h b/tests/unit/set2/set_type_std.h index d359537b..927334db 100644 --- a/tests/unit/set2/set_type_std.h +++ b/tests/unit/set2/set_type_std.h @@ -42,7 +42,7 @@ namespace set2 { {} template - bool find( const Key& key ) + bool contains( const Key& key ) { scoped_lock al( m_lock ); return base_class::find( value_type(key) ) != base_class::end(); @@ -125,7 +125,7 @@ namespace set2 { {} template - bool find( const Key& key ) + bool contains( const Key& key ) { value_type v( key ); scoped_lock al( m_lock );