3 #include "set2/set_type.h"
4 #include "cppunit/thread.h"
8 #define TEST_CASE(TAG, X) void X();
10 class Set_InsDelFind: public CppUnitMini::TestCase
13 size_t c_nSetSize = 500000; // initial set size
14 size_t c_nThreadCount = 8; // thread count
15 size_t c_nMaxLoadFactor = 8; // maximum load factor
16 unsigned int c_nInsertPercentage = 5;
17 unsigned int c_nDeletePercentage = 5;
18 unsigned int c_nDuration = 30; // test duration, seconds
19 bool c_bPrintGCState = true;
21 size_t c_nCuckooInitialSize = 1024;// initial size for CuckooSet
22 size_t c_nCuckooProbesetSize = 16; // CuckooSet probeset size (only for list-based probeset)
23 size_t c_nCuckooProbesetThreshold = 0; // CUckooSet probeset threshold (0 - use default)
25 size_t c_nMultiLevelSet_HeadBits = 10;
26 size_t c_nMultiLevelSet_ArrayBits = 4;
28 size_t c_nLoadFactor = 2;
37 static const unsigned int c_nShuffleSize = 100;
38 actions m_arrShuffle[c_nShuffleSize];
41 typedef CppUnitMini::TestCase Base;
42 typedef size_t key_type;
43 typedef size_t value_type;
46 class WorkThread: public CppUnitMini::TestThread
50 virtual WorkThread * clone()
52 return new WorkThread( *this );
55 size_t m_nInsertSuccess;
56 size_t m_nInsertFailed;
57 size_t m_nDeleteSuccess;
58 size_t m_nDeleteFailed;
59 size_t m_nFindSuccess;
63 WorkThread( CppUnitMini::ThreadPool& pool, Set& rMap )
64 : CppUnitMini::TestThread( pool )
67 WorkThread( WorkThread& src )
68 : CppUnitMini::TestThread( src )
72 Set_InsDelFind& getTest()
74 return reinterpret_cast<Set_InsDelFind&>( m_Pool.m_Test );
77 virtual void init() { cds::threading::Manager::attachThread() ; }
78 virtual void fini() { cds::threading::Manager::detachThread() ; }
91 actions * pAct = getTest().m_arrShuffle;
93 size_t const nNormalize = size_t(-1) / ( getTest().c_nSetSize * 2);
96 while ( !time_elapsed() ) {
97 nRand = cds::bitop::RandXorShift(nRand);
98 size_t n = nRand / nNormalize;
101 if ( rMap.contains( n ))
107 if ( rMap.insert( n ))
113 if ( rMap.erase( n ))
120 if ( ++i >= c_nShuffleSize )
128 void do_test( Set& testSet )
130 typedef WorkThread<Set> work_thread;
132 // fill map - only odd number
134 size_t * pInitArr = new size_t[ c_nSetSize ];
135 size_t * pEnd = pInitArr + c_nSetSize;
136 for ( size_t i = 0; i < c_nSetSize; ++i )
137 pInitArr[i] = i * 2 + 1;
138 shuffle( pInitArr, pEnd );
139 for ( size_t * p = pInitArr; p < pEnd; ++p )
140 testSet.insert( typename Set::value_type( *p, *p ) );
144 cds::OS::Timer timer;
146 CppUnitMini::ThreadPool pool( *this );
147 pool.add( new work_thread( pool, testSet ), c_nThreadCount );
148 pool.run( c_nDuration );
149 CPPUNIT_MSG( " Duration=" << pool.avgDuration() );
151 size_t nInsertSuccess = 0;
152 size_t nInsertFailed = 0;
153 size_t nDeleteSuccess = 0;
154 size_t nDeleteFailed = 0;
155 size_t nFindSuccess = 0;
156 size_t nFindFailed = 0;
157 for ( CppUnitMini::ThreadPool::iterator it = pool.begin(); it != pool.end(); ++it ) {
158 work_thread * pThread = static_cast<work_thread *>( *it );
159 assert( pThread != nullptr );
160 nInsertSuccess += pThread->m_nInsertSuccess;
161 nInsertFailed += pThread->m_nInsertFailed;
162 nDeleteSuccess += pThread->m_nDeleteSuccess;
163 nDeleteFailed += pThread->m_nDeleteFailed;
164 nFindSuccess += pThread->m_nFindSuccess;
165 nFindFailed += pThread->m_nFindFailed;
168 size_t nTotalOps = nInsertSuccess + nInsertFailed + nDeleteSuccess + nDeleteFailed + nFindSuccess + nFindFailed;
170 CPPUNIT_MSG( " Totals (success/failed): \n\t"
171 << " Insert=" << nInsertSuccess << '/' << nInsertFailed << "\n\t"
172 << " Delete=" << nDeleteSuccess << '/' << nDeleteFailed << "\n\t"
173 << " Find=" << nFindSuccess << '/' << nFindFailed << "\n\t"
174 << " Speed=" << (nFindSuccess + nFindFailed) / c_nDuration << " find/sec\n\t"
175 << " " << (nInsertSuccess + nDeleteSuccess) / c_nDuration << " modify/sec\n\t"
176 << " Total ops=" << nTotalOps << "\n\t"
177 << " speed=" << nTotalOps / c_nDuration << " ops/sec\n\t"
178 << " Set size=" << testSet.size()
182 CPPUNIT_MSG( " Clear map (single-threaded)..." );
185 CPPUNIT_MSG( " Duration=" << timer.duration() );
186 CPPUNIT_CHECK_EX( testSet.empty(), ((long long) testSet.size()) );
188 additional_check( testSet );
189 print_stat( testSet );
190 additional_cleanup( testSet );
196 CPPUNIT_MSG( "Thread count=" << c_nThreadCount
197 << " initial map size=" << c_nSetSize
198 << " insert=" << c_nInsertPercentage << '%'
199 << " delete=" << c_nDeletePercentage << '%'
200 << " duration=" << c_nDuration << "s"
203 if ( Set::c_bLoadFactorDepended ) {
204 for ( c_nLoadFactor = 1; c_nLoadFactor <= c_nMaxLoadFactor; c_nLoadFactor *= 2 ) {
205 CPPUNIT_MSG(" LoadFactor = " << c_nLoadFactor );
208 if ( c_bPrintGCState )
215 if ( c_bPrintGCState )
220 void setUpParams( const CppUnitMini::TestCfg& cfg );
222 # include "set2/set_defs.h"
223 CDSUNIT_DECLARE_MichaelSet
224 CDSUNIT_DECLARE_SplitList
225 CDSUNIT_DECLARE_StripedSet
226 CDSUNIT_DECLARE_RefinableSet
227 CDSUNIT_DECLARE_CuckooSet
228 CDSUNIT_DECLARE_SkipListSet
229 CDSUNIT_DECLARE_EllenBinTreeSet
230 CDSUNIT_DECLARE_MultiLevelHashSet
231 CDSUNIT_DECLARE_StdSet
233 CPPUNIT_TEST_SUITE_(Set_InsDelFind, "Map_InsDelFind")
234 CDSUNIT_TEST_MichaelSet
235 CDSUNIT_TEST_SplitList
236 CDSUNIT_TEST_SkipListSet
237 CDSUNIT_TEST_MultiLevelHashSet
238 CDSUNIT_TEST_EllenBinTreeSet
239 CDSUNIT_TEST_StripedSet
240 CDSUNIT_TEST_RefinableSet
241 CDSUNIT_TEST_CuckooSet
243 CPPUNIT_TEST_SUITE_END();