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 size_t key_type;
42 typedef size_t value_type;
45 class WorkThread: public CppUnitMini::TestThread
49 virtual WorkThread * clone()
51 return new WorkThread( *this );
54 size_t m_nInsertSuccess;
55 size_t m_nInsertFailed;
56 size_t m_nDeleteSuccess;
57 size_t m_nDeleteFailed;
58 size_t m_nFindSuccess;
62 WorkThread( CppUnitMini::ThreadPool& pool, Set& rMap )
63 : CppUnitMini::TestThread( pool )
66 WorkThread( WorkThread& src )
67 : CppUnitMini::TestThread( src )
71 Set_InsDelFind& getTest()
73 return reinterpret_cast<Set_InsDelFind&>( m_Pool.m_Test );
76 virtual void init() { cds::threading::Manager::attachThread() ; }
77 virtual void fini() { cds::threading::Manager::detachThread() ; }
90 actions * pAct = getTest().m_arrShuffle;
92 size_t const nNormalize = size_t(-1) / ( getTest().c_nSetSize * 2);
95 while ( !time_elapsed() ) {
96 nRand = cds::bitop::RandXorShift(nRand);
97 size_t n = nRand / nNormalize;
100 if ( rMap.contains( n ))
106 if ( rMap.insert( n ))
112 if ( rMap.erase( n ))
119 if ( ++i >= c_nShuffleSize )
127 void do_test( Set& testSet )
129 typedef WorkThread<Set> work_thread;
131 // fill map - only odd number
133 size_t * pInitArr = new size_t[ c_nSetSize ];
134 size_t * pEnd = pInitArr + c_nSetSize;
135 for ( size_t i = 0; i < c_nSetSize; ++i )
136 pInitArr[i] = i * 2 + 1;
137 shuffle( pInitArr, pEnd );
138 for ( size_t * p = pInitArr; p < pEnd; ++p )
139 testSet.insert( typename Set::value_type( *p, *p ) );
143 cds::OS::Timer timer;
145 CppUnitMini::ThreadPool pool( *this );
146 pool.add( new work_thread( pool, testSet ), c_nThreadCount );
147 pool.run( c_nDuration );
148 CPPUNIT_MSG( " Duration=" << pool.avgDuration() );
150 size_t nInsertSuccess = 0;
151 size_t nInsertFailed = 0;
152 size_t nDeleteSuccess = 0;
153 size_t nDeleteFailed = 0;
154 size_t nFindSuccess = 0;
155 size_t nFindFailed = 0;
156 for ( CppUnitMini::ThreadPool::iterator it = pool.begin(); it != pool.end(); ++it ) {
157 work_thread * pThread = static_cast<work_thread *>( *it );
158 assert( pThread != nullptr );
159 nInsertSuccess += pThread->m_nInsertSuccess;
160 nInsertFailed += pThread->m_nInsertFailed;
161 nDeleteSuccess += pThread->m_nDeleteSuccess;
162 nDeleteFailed += pThread->m_nDeleteFailed;
163 nFindSuccess += pThread->m_nFindSuccess;
164 nFindFailed += pThread->m_nFindFailed;
167 size_t nTotalOps = nInsertSuccess + nInsertFailed + nDeleteSuccess + nDeleteFailed + nFindSuccess + nFindFailed;
169 CPPUNIT_MSG( " Totals (success/failed): \n\t"
170 << " Insert=" << nInsertSuccess << '/' << nInsertFailed << "\n\t"
171 << " Delete=" << nDeleteSuccess << '/' << nDeleteFailed << "\n\t"
172 << " Find=" << nFindSuccess << '/' << nFindFailed << "\n\t"
173 << " Speed=" << (nFindSuccess + nFindFailed) / c_nDuration << " find/sec\n\t"
174 << " " << (nInsertSuccess + nDeleteSuccess) / c_nDuration << " modify/sec\n\t"
175 << " Total ops=" << nTotalOps << "\n\t"
176 << " speed=" << nTotalOps / c_nDuration << " ops/sec\n\t"
177 << " Set size=" << testSet.size()
181 CPPUNIT_MSG( " Clear map (single-threaded)..." );
184 CPPUNIT_MSG( " Duration=" << timer.duration() );
185 CPPUNIT_CHECK_EX( testSet.empty(), ((long long) testSet.size()) );
187 additional_check( testSet );
188 print_stat( testSet );
189 additional_cleanup( testSet );
195 CPPUNIT_MSG( "Thread count=" << c_nThreadCount
196 << " initial map size=" << c_nSetSize
197 << " insert=" << c_nInsertPercentage << '%'
198 << " delete=" << c_nDeletePercentage << '%'
199 << " duration=" << c_nDuration << "s"
202 if ( Set::c_bLoadFactorDepended ) {
203 for ( c_nLoadFactor = 1; c_nLoadFactor <= c_nMaxLoadFactor; c_nLoadFactor *= 2 ) {
204 CPPUNIT_MSG(" LoadFactor = " << c_nLoadFactor );
207 if ( c_bPrintGCState )
214 if ( c_bPrintGCState )
219 void setUpParams( const CppUnitMini::TestCfg& cfg );
221 # include "set2/set_defs.h"
222 CDSUNIT_DECLARE_MichaelSet
223 CDSUNIT_DECLARE_SplitList
224 CDSUNIT_DECLARE_StripedSet
225 CDSUNIT_DECLARE_RefinableSet
226 CDSUNIT_DECLARE_CuckooSet
227 CDSUNIT_DECLARE_SkipListSet
228 CDSUNIT_DECLARE_EllenBinTreeSet
229 CDSUNIT_DECLARE_MultiLevelHashSet
230 CDSUNIT_DECLARE_StdSet
232 CPPUNIT_TEST_SUITE_(Set_InsDelFind, "Map_InsDelFind")
233 CDSUNIT_TEST_MichaelSet
234 CDSUNIT_TEST_SplitList
235 CDSUNIT_TEST_SkipListSet
236 CDSUNIT_TEST_MultiLevelHashSet
237 CDSUNIT_TEST_EllenBinTreeSet
238 CDSUNIT_TEST_StripedSet
239 CDSUNIT_TEST_RefinableSet
240 CDSUNIT_TEST_CuckooSet
242 CPPUNIT_TEST_SUITE_END();