int runs = 1000;
int upperKB = 50;
JCS jcs = JCS.getInstance( ( numPerRun / 2 ) + "aSecond" );
ElapsedTimer timer = new ElapsedTimer();
int numToGet = numPerRun * ( runs / 10 );
for ( int i = 0; i < numToGet; i++ )
{
jcs.get( String.valueOf( i ) );
}
System.out.println( LOG_DIVIDER );
System.out.println( "After getting " + numToGet );
System.out.println( "Elapsed " + timer.getElapsedTimeString() );
logMemoryUsage();
jcs.clear();
Thread.sleep( 3000 );
System.out.println( LOG_DIVIDER );
System.out.println( "Start putting" );
long totalSize = 0;
int totalPut = 0;
Random random = new Random( 89 );
while ( runCount < runs )
{
runCount++;
for ( int i = 0; i < numPerRun; i++ )
{
// 1/2 upper to upperKB-4 KB
int kiloBytes = Math.max( upperKB / 2, random.nextInt( upperKB ) );
int bytes = ( kiloBytes ) * 1024;
totalSize += bytes;
totalPut++;
DiskTestObject object = new DiskTestObject( new Integer( i ), new byte[bytes] );
jcs.put( String.valueOf( totalPut ), object );
}
// get half of those inserted the previous run
if ( runCount > 1 )
{
for ( int j = ( ( totalPut - numPerRun ) - ( numPerRun / 2 ) ); j < ( totalPut - numPerRun ); j++ )
{
jcs.get( String.valueOf( j ) );
}
}
// remove half of those inserted the previous run
if ( runCount > 1 )
{
for ( int j = ( ( totalPut - numPerRun ) - ( numPerRun / 2 ) ); j < ( totalPut - numPerRun ); j++ )
{
jcs.remove( String.valueOf( j ) );
}
}
Thread.sleep( pauseBetweenRuns );
if ( runCount % 1 == 0 )
{
System.out.println( LOG_DIVIDER );
System.out.println( "Elapsed " + timer.getElapsedTimeString() );
System.out.println( "Run count: " + runCount + " Average size: " + ( totalSize / totalPut ) + "\n"
+ jcs.getStats() );
logMemoryUsage();
}
}