Beispiel #1
0
    void Map_find_string::setUpParams( const CppUnitMini::TestCfg& cfg )
    {
        c_nThreadCount = cfg.getSizeT("ThreadCount", c_nThreadCount );
        c_nMapSize = cfg.getSizeT("MapSize", c_nMapSize);
        c_nPercentExists = cfg.getSizeT("PercentExists", c_nPercentExists);
        c_nPassCount = cfg.getSizeT("PassCount", c_nPassCount);
        c_nMaxLoadFactor = cfg.getSizeT("MaxLoadFactor", c_nMaxLoadFactor);
        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);

        c_nFeldmanMap_HeadBits = cfg.getSizeT("FeldmanMapHeadBits", c_nFeldmanMap_HeadBits);
        c_nFeldmanMap_ArrayBits = cfg.getSizeT("FeldmanMapArrayBits", c_nFeldmanMap_ArrayBits);

        if ( c_nThreadCount == 0 )
            c_nThreadCount = std::thread::hardware_concurrency();

        CPPUNIT_MSG( "Generating test data...\n");
        cds::OS::Timer    timer;
        generateSequence();
        CPPUNIT_MSG( "   Duration=" << timer.duration() << "\n" );

    }
Beispiel #2
0
        void test( size_t nThreadCount )
        {
            ALLOC alloc;
            cds::OS::Timer    timer;

            CPPUNIT_MSG( "Thread count=" << nThreadCount );
            s_nPassPerThread = s_nPassCount / nThreadCount;

            CppUnitMini::ThreadPool pool( *this );
            pool.add( new Thread<ALLOC>( pool, alloc ), nThreadCount );
            pool.run();
            CPPUNIT_MSG( "  Duration=" << pool.avgDuration() );
        }
    void Map_find_string::initTestSequence()
    {
        if ( !m_bSeqInit ) {
            m_bSeqInit = true;

            CPPUNIT_MSG( "Generating test data...");
            cds::OS::Timer    timer;
            generateSequence();
            CPPUNIT_MSG( "   Duration=" << timer.duration() );
            CPPUNIT_MSG( "Map size=" << m_nRealMapSize << " find key loop=" << m_Arr.size() << " (" << c_nPercentExists << "% success)" );
            CPPUNIT_MSG( "Thread count=" << c_nThreadCount << " Pass count=" << c_nPassCount );
        }
    }
        void test( bool bStat )
        {
            CPPUNIT_MSG( "Block size=" << s_nMinBlockSize << "-" << s_nMaxBlockSize 
                << ", block count per thread=" << s_nBlocksPerThread << ", pass count=" << s_nPassCount ) ;

            for ( size_t nThreadCount = 2; nThreadCount <= s_nMaxThreadCount; nThreadCount *= 2 ) {
                summary_stat stBegin    ;
                if ( bStat )
                    ALLOC::stat(stBegin)    ;

                test<ALLOC>( nThreadCount ) ;

                summary_stat    stEnd   ;
                if ( bStat ) {
                    ALLOC::stat( stEnd ) ;

                    std::cout << "\nStatistics:\n"
                        << stEnd
                        ;
                    stEnd -= stBegin    ;
                    std::cout << "\nDelta statistics:\n"
                        << stEnd
                        ;
                }
            }
        }
            virtual void test()
            {
                size_t nPushCount = getTest().m_nThreadPushCount;
                Cacheline v;

                for (size_t i = 0; i < nPushCount; i++) {
                    while (! m_Bag.tryRemoveAny( v ) )
                        ;
#ifdef _DEBUG
                    CPPUNIT_MSG( "Removed " << v.nNo );
#endif
                }

#ifdef _DEBUG
                    CPPUNIT_MSG( "Consumer finished." );
#endif
            }
Beispiel #6
0
        void test( size_t nThreadCount )
        {
            ALLOC alloc;

            CPPUNIT_MSG( "Thread count=" << nThreadCount );
            CPPUNIT_MSG("Initialize data..." );

            randomGen<unsigned int> rndGen;

            s_nPassPerThread = s_nPassCount / nThreadCount;

            size_t nThread;
            m_aThreadData = new thread_data[ nThreadCount ];
            for ( nThread = 0; nThread < nThreadCount; ++nThread ) {
                thread_data thData
                    = m_aThreadData[nThread]
                    = new char *[ s_nBlocksPerThread ];
                    for ( size_t i = 0; i < s_nBlocksPerThread; ++i ) {
                        thData[i] = reinterpret_cast<char *>(alloc.allocate( rndGen( s_nMinBlockSize, s_nMaxBlockSize ), nullptr ));
                        CPPUNIT_ASSERT( (reinterpret_cast<uintptr_t>(thData[i]) & (ALLOC::alignment - 1)) == 0 );
                    }
            }
            CPPUNIT_MSG("Initializatin done" );

            CppUnitMini::ThreadPool pool( *this );
            pool.add( new Thread<ALLOC>( pool, alloc ), nThreadCount );
            nThread = 0;
            for ( CppUnitMini::ThreadPool::iterator it = pool.begin(); it != pool.end(); ++it )
                static_cast<Thread<ALLOC> *>(*it)->m_arr = m_aThreadData[nThread++];

            cds::OS::Timer    timer;
            pool.run();
            CPPUNIT_MSG( "  Duration=" << pool.avgDuration() );

            for ( nThread = 0; nThread < nThreadCount; ++nThread ) {
                thread_data thData = m_aThreadData[nThread];
                for ( size_t i = 0; i < s_nBlocksPerThread; ++i ) {
                    alloc.deallocate( reinterpret_cast<typename ALLOC::value_type *>(thData[i]), 1 );
                }
                delete [] thData;
            }
            delete [] m_aThreadData;
        }
Beispiel #7
0
        void test( size_t nThreadCount )
        {
            ALLOC alloc ;

            CPPUNIT_MSG( "Thread count=" << nThreadCount )  ;
            s_nPassPerThread = s_nPassCount / nThreadCount  ;

            CppUnitMini::ThreadPool pool( *this )   ;
            pool.add( new Thread<ALLOC>( pool, alloc ), nThreadCount ) ;

            cds::OS::Timer    timer    ;
            pool.run()  ;
            CPPUNIT_MSG( "  Duration=" << pool.avgDuration() ) ;

            for ( size_t i = 0; i < m_Data.size(); ++i ) {
                if ( m_Data[i].m_pszBlock ) {
                    alloc.deallocate( m_Data[i].m_pszBlock, 1 ) ;
                    m_Data[i].m_pszBlock = NULL ;
                }
            }
        }
            virtual void test()
            {
                size_t nPushCount = getTest().m_nThreadPushCount;
                Cacheline v;

                for (v.nNo = 0; v.nNo < nPushCount; ++v.nNo) {
                    m_Bag.add( v );
#if _DEBUG
                    // Just so writer and reader have approximate "computation"
                    CPPUNIT_MSG( "Added " << v.nNo );
#endif
                }
            }
    void IntrusiveCuckooSetHdrTest::Cuckoo_refinable_vector_basehook_sort_cmpmix_stat()
    {
        typedef IntrusiveCuckooSetHdrTest::base_item< ci::cuckoo::node< ci::cuckoo::vector<8>, 0 > >  item_type   ;

        typedef ci::CuckooSet< item_type
            ,ci::cuckoo::make_traits<
                ci::opt::hook< ci::cuckoo::base_hook<
                    ci::cuckoo::probeset_type< item_type::probeset_type >
                > >
                ,co::mutex_policy< ci::cuckoo::refinable<> >
                ,co::hash< std::tuple< hash1, hash2 > >
                ,co::less< IntrusiveCuckooSetHdrTest::less<item_type> >
                ,co::compare< IntrusiveCuckooSetHdrTest::cmp<item_type> >
                ,co::stat< ci::cuckoo::stat >
            >::type
        > set_type ;

        unsigned int nProbesetSize = set_type::node_type::probeset_size ? set_type::node_type::probeset_size : 4 ;
        set_type s( 256, nProbesetSize, nProbesetSize / 2 )  ;
        test_with( s )  ;
        CPPUNIT_MSG( s.statistics() << s.mutex_policy_statistics() ) ;
    }
Beispiel #10
0
    void cut_uint_le()
    {
        CPPUNIT_MSG("little-endian byte order");

        typedef cds::algo::split_bitstring< size_t > split_bitstring;

        size_t src = sizeof(src) == 8 ? 0xFEDCBA9876543210 : 0x76543210;
        split_bitstring splitter(src);
        size_t res;

        // Trivial case
        CPPUNIT_ASSERT( !splitter.eos() );
        CPPUNIT_ASSERT( splitter );
        res = splitter.cut(sizeof(src) * 8);
        CPPUNIT_ASSERT_EX( res == src, "src=" << src << ", result=" << res );
        CPPUNIT_ASSERT( splitter.eos() );
        CPPUNIT_ASSERT( !splitter );
        CPPUNIT_ASSERT(splitter.safe_cut(sizeof(src) * 8) == 0 );
        CPPUNIT_ASSERT( splitter.eos() );
        CPPUNIT_ASSERT( !splitter );
        splitter.reset();
        CPPUNIT_ASSERT( !splitter.eos() );
        CPPUNIT_ASSERT( splitter );
        res = splitter.cut(sizeof(src) * 8);
        CPPUNIT_ASSERT_EX( res == src, "src=" << src << ", result=" << res );
        CPPUNIT_ASSERT( splitter.eos() );
        CPPUNIT_ASSERT( !splitter );
        CPPUNIT_ASSERT(splitter.safe_cut(sizeof(src) * 8) == 0 );
        CPPUNIT_ASSERT( splitter.eos() );
        CPPUNIT_ASSERT( !splitter );

        // Cut each hex digit
        splitter.reset();
        for ( size_t i = 0; i < sizeof(size_t) * 2; ++i ) {
            CPPUNIT_ASSERT( !splitter.eos() );
            CPPUNIT_ASSERT( splitter );
            CPPUNIT_ASSERT( splitter.cut( 4 ) == i );
        }
        CPPUNIT_ASSERT( splitter.eos() );
        CPPUNIT_ASSERT( !splitter );

        // by one bit
        {
            splitter.reset();
            res = 0;
            for ( size_t i = 0; i < sizeof(size_t) * 8; ++i ) {
                CPPUNIT_ASSERT( !splitter.eos() );
                CPPUNIT_ASSERT( splitter );
                res = res + (splitter.cut( 1 ) << i);
            }
            CPPUNIT_ASSERT( splitter.eos() );
            CPPUNIT_ASSERT( !splitter );
            CPPUNIT_ASSERT( res == src );
        }

        // random cut
        {
            for ( size_t k = 0; k < 100; ++k ) {
                splitter.reset();
                res = 0;
                size_t shift = 0;
                while ( splitter ) {
                    CPPUNIT_ASSERT( !splitter.eos() );
                    CPPUNIT_ASSERT( splitter );
                    int bits = rand() % 16;
                    res = res + ( splitter.safe_cut( bits ) << shift );
                    shift += bits;
                }
                CPPUNIT_ASSERT( splitter.eos() );
                CPPUNIT_ASSERT( !splitter );
                CPPUNIT_ASSERT( res == src );
            }
        }
    }