bloritsch    2002/06/26 14:12:50

  Modified:    collections/src/test/org/apache/avalon/excalibur/collections/test
                        ThreadedMapTest.java
  Log:
  Try to make the tests as fair as possible
  
  Revision  Changes    Path
  1.4       +41 -23    
jakarta-avalon-excalibur/collections/src/test/org/apache/avalon/excalibur/collections/test/ThreadedMapTest.java
  
  Index: ThreadedMapTest.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-avalon-excalibur/collections/src/test/org/apache/avalon/excalibur/collections/test/ThreadedMapTest.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ThreadedMapTest.java      26 Jun 2002 20:20:46 -0000      1.3
  +++ ThreadedMapTest.java      26 Jun 2002 21:12:49 -0000      1.4
  @@ -26,11 +26,7 @@
   public class ThreadedMapTest extends TestCase
   {
       private static final int ITERATIONS = 10000;
  -    private static final int THREADS = 20;
  -
  -    private MapStart start;
  -
  -    private Map queue;
  +    private static final int THREADS = 100;
   
       private MapStart[] stages;
   
  @@ -38,8 +34,18 @@
       {
           super( name );
       }
  -
  -    public void testThreaded() throws Exception
  +    
  +    public void setUp()
  +    {
  +        System.gc();
  +    }
  +    
  +    public void tearDown()
  +    {
  +        System.gc();
  +    }
  +    
  +    public void testBucketMapSizedThreaded() throws Exception
       {
           initialize( ITERATIONS, THREADS, new BucketMap( ( ITERATIONS / 2 ) + 
1) );
           long start = System.currentTimeMillis();
  @@ -48,27 +54,36 @@
   
           System.out.println("BucketMap (" + ((ITERATIONS / 2) + 1) + " 
buckets) took " + (end - start) + "ms");
           System.out.println("Thats " + ( (float)(end - start) / 
(float)(ITERATIONS * THREADS) ) + "ms per operation");
  -
  +    }
  +    
  +    public void testBucketMapUnsizedThreaded() throws Exception
  +    {
           initialize( ITERATIONS, THREADS, new BucketMap() );
  -        start = System.currentTimeMillis();
  +        long start = System.currentTimeMillis();
           start();
  -        end = System.currentTimeMillis();
  +        long end = System.currentTimeMillis();
   
           System.out.println("Unsized BucketMap (255 buckets) took " + (end - 
start) + "ms");
           System.out.println("Thats " + ( (float)(end - start) / 
(float)(ITERATIONS * THREADS) ) + "ms per operation");
  +    }
   
  +    public void testSynchronizedHashMapSizedThreaded() throws Exception
  +    {
           initialize( ITERATIONS, THREADS, Collections.synchronizedMap(new 
HashMap(((ITERATIONS / 2) + 1))) );
  -        start = System.currentTimeMillis();
  +        long start = System.currentTimeMillis();
           start();
  -        end = System.currentTimeMillis();
  +        long end = System.currentTimeMillis();
   
           System.out.println("Synchronized (sized) HashMap took " + (end - 
start) + "ms");
           System.out.println("Thats " + ( (float)(end - start) / 
(float)(ITERATIONS * THREADS) ) + "ms per operation");
  +    }
   
  +    public void testSynchronizedHashMapUnsizedThreaded() throws Exception
  +    {
           initialize( ITERATIONS, THREADS, Collections.synchronizedMap(new 
HashMap()) );
  -        start = System.currentTimeMillis();
  +        long start = System.currentTimeMillis();
           start();
  -        end = System.currentTimeMillis();
  +        long end = System.currentTimeMillis();
   
           System.out.println("Synchronized (unsized) HashMap took " + (end - 
start) + "ms");
           System.out.println("Thats " + ( (float)(end - start) / 
(float)(ITERATIONS * THREADS) ) + "ms per operation");
  @@ -129,21 +144,24 @@
   
           public void run()
           {
  -            long seed = 0;
  +            int seed = 0;
               Random rnd = new Random(seed);
  -            
  -            for( int i = 0; i < this.mapCount / 2; i++ )
  +
  +            for( int i = 0; i < this.mapCount / 4; i++ )
               {
  -                this.map.put(new Integer( rnd.nextInt() ), new Integer( 
rnd.nextInt() ) );
  +                this.map.put(new Integer( i ), new Integer( i * 5 ) );
  +                this.count++;
  +                this.map.put(new Integer(rnd.nextInt()), new 
Integer(rnd.nextInt()) );
                   this.count++;
               }
  +
  +            rnd.setSeed(seed);
               
  -            rnd.setSeed( seed ); // reset pseudo random
  -            
  -            for( int i = 0; i < this.mapCount / 2; i++ )
  +            for( int i = 0; i < this.mapCount / 4; i++ )
               {
  -                Integer value = (Integer)this.map.get( new Integer( 
rnd.nextInt() ));
  -                assertEquals(value.intValue(), rnd.nextInt());
  +                Integer value = (Integer)this.map.get( new Integer( i * 5 ));
  +                this.count++;
  +                value = (Integer)this.map.get( new Integer( rnd.nextInt() ));
                   this.count++;
               }
           }
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to