コード例 #1
0
ファイル: instanceCache.cpp プロジェクト: VMML/Collage
 virtual void run()
 {
     size_t hits = 0;
     size_t ops = 0;
     while( _clock.getTime64() < RUNTIME )
     {
         const co::uint128_t key( _rng.get< uint16_t >(), 0 );
         if( _cache[ key ] != co::InstanceCache::Data::NONE )
         {
             ++hits;
             _cache.release( key, 1 );
         }
         ++ops;
     }
     const uint64_t time = _clock.getTime64();
     std::cout << hits << " read hits in " << ops << " operations, "
               << ops / time << " ops/ms" << std::endl;
 }
コード例 #2
0
int main( const int argc, char** argv )
{
    eq::NodeFactory nodeFactory;
    TEST( eq::init( argc, argv, &nodeFactory ));

    eq::Config* config = eq::getConfig( argc, argv );
    TEST( config );

    size_t nLoops = 0;
    const lunchbox::Clock clock;
    while( clock.getTime64() < RUNTIME )
    {
        TEST( config->update( ));
        ++nLoops;
    }
    const float time = clock.getTimef();

    std::cout << nLoops << " Config::update in " << time << " ms (" << 
        time/float(nLoops) << " ms/update)" << std::endl;

    eq::releaseConfig( config );
    eq::exit();
    return EXIT_SUCCESS;
}
コード例 #3
0
ファイル: instanceCache.cpp プロジェクト: VMML/Collage
int main( int argc, char **argv )
{
    co::init( argc, argv );
    co::ObjectDataOCommand out( co::Connections(), co::CMD_NODE_OBJECT_INSTANCE,
                                co::COMMANDTYPE_NODE, co::uint128_t(), 0,
                                co::uint128_t(1), 0, 0, COMMAND_SIZE, true, 0 );
    co::LocalNodePtr node = new co::LocalNode;
    co::ObjectDataICommand in = out._getCommand( node );
    TESTINFO( in.isValid(), in );
    TEST( in.isLast( ));

    Reader** readers = static_cast< Reader** >(
        alloca( N_READER * sizeof( Reader* )));

    co::InstanceCache cache;
    lunchbox::RNG rng;

    size_t hits = 0;
    size_t ops = 0;

    for( co::uint128_t key; key.low() < 65536; ++key ) // Fill cache
        if( !cache.add( co::ObjectVersion( key, co::uint128_t(1) ), 1, in ))
            break;

    _clock.reset();
    for( size_t i = 0; i < N_READER; ++i )
    {
        readers[ i ] = new Reader( cache );
        readers[ i ]->start();
    }

    while( _clock.getTime64() < RUNTIME )
    {
        const co::uint128_t id( 0, rng.get< uint16_t >( ));
        const co::ObjectVersion key( id, co::uint128_t(1) );
        if( cache[ key.identifier ] != co::InstanceCache::Data::NONE )
        {
            TEST( cache.release( key.identifier, 1 ));
            ++ops;
            if( cache.erase( key.identifier ))
            {
                TEST( cache.add( key, 1, in ));
                ops += 2;
                hits += 2;
            }
        }
        else if( cache.add( key, 1, in ))
            ++hits;
        ++ops;
    }

    const uint64_t time = _clock.getTime64();
    std::cout << hits << " write hits in " << ops << " operations, "
              << ops / time << " ops/ms" << std::endl;

    for( size_t i = 0; i < N_READER; ++i )
    {
        readers[ i ]->join();
        delete readers[ i ];
    }

    std::cout << cache << std::endl;

    for( co::uint128_t key; key.low() < 65536; ++key ) // Fill cache
    {
        if( cache[ key ] != co::InstanceCache::Data::NONE )
        {
            TEST( cache.release( key, 1 ));
            TEST( cache.erase( key ));
        }
    }

    for( co::uint128_t key; key.low() < 65536; ++key ) // Fill cache
    {
        TEST( cache[ key ] == co::InstanceCache::Data::NONE );
    }

    std::cout << cache << std::endl;

    TESTINFO( cache.getSize() == 0, cache.getSize( ));
    TEST( co::exit( ));
    return EXIT_SUCCESS;
}