Bugfix
[libcds.git] / tests / unit / map2 / map_find_int.cpp
1 //$$CDS-header$$
2
3 #include "map2/map_find_int.h"
4
5 // find int test in map<int> in mutithreaded mode
6 namespace map2 {
7     CPPUNIT_TEST_SUITE_REGISTRATION( Map_find_int );
8
9     void Map_find_int::generateSequence()
10     {
11         size_t nPercent = c_nPercentExists;
12
13         if ( nPercent > 100 )
14             nPercent = 100;
15         else if ( nPercent < 1 )
16             nPercent = 1;
17
18         m_nRealMapSize = 0;
19
20         m_Arr.resize( c_nMapSize );
21         for ( size_t i = 0; i < c_nMapSize; ++i ) {
22             m_Arr[i].nKey = i * 13;
23             m_Arr[i].bExists = CppUnitMini::Rand( 100 ) <= nPercent;
24             if ( m_Arr[i].bExists )
25                 ++m_nRealMapSize;
26         }
27         shuffle( m_Arr.begin(), m_Arr.end() );
28     }
29
30     void Map_find_int::setUpParams( const CppUnitMini::TestCfg& cfg )
31     {
32         c_nThreadCount = cfg.getSizeT("ThreadCount", c_nThreadCount );
33         c_nMapSize = cfg.getSizeT("MapSize", c_nMapSize);
34         c_nPercentExists = cfg.getSizeT("PercentExists", c_nPercentExists);
35         c_nPassCount = cfg.getSizeT("PassCount", c_nPassCount);
36         c_nMaxLoadFactor = cfg.getSizeT("MaxLoadFactor", c_nMaxLoadFactor);
37         c_bPrintGCState = cfg.getBool("PrintGCStateFlag", c_bPrintGCState );
38
39         c_nCuckooInitialSize = cfg.getSizeT("CuckooInitialSize", c_nCuckooInitialSize);
40         c_nCuckooProbesetSize = cfg.getSizeT("CuckooProbesetSize", c_nCuckooProbesetSize);
41         c_nCuckooProbesetThreshold = cfg.getSizeT("CuckooProbesetThreshold", c_nCuckooProbesetThreshold);
42
43         c_nMultiLevelMap_HeadBits = cfg.getSizeT("MultiLevelMapHeadBits", c_nMultiLevelMap_HeadBits);
44         c_nMultiLevelMap_ArrayBits = cfg.getSizeT("MultiLevelMapArrayBits", c_nMultiLevelMap_ArrayBits);
45
46         if ( c_nThreadCount == 0 )
47             c_nThreadCount = std::thread::hardware_concurrency();
48
49         CPPUNIT_MSG( "Generating test data...");
50         cds::OS::Timer    timer;
51         generateSequence();
52         CPPUNIT_MSG( "   Duration=" << timer.duration() );
53         CPPUNIT_MSG( "Map size=" << m_nRealMapSize << " find key loop=" << m_Arr.size() << " (" << c_nPercentExists << "% success)" );
54         CPPUNIT_MSG( "Thread count=" << c_nThreadCount << " Pass count=" << c_nPassCount );
55     }
56 } // namespace map