FileDocCategorySizeDatePackage
MapPerformance.javaAPI DocExample4402Mon Apr 06 18:10:26 BST 1998c08.newcollections

MapPerformance

public class MapPerformance extends Object

Fields Summary
private static final int
REPS
private static Tester[]
tests
Constructors Summary
Methods Summary
public static java.util.Mapfill(java.util.Map m, int size)

         
    for(int i = 0; i < size; i++) {
      String x = Integer.toString(i);
      m.put(x, x);
    }
    return m;
  
public static voidmain(java.lang.String[] args)

    // Small:
    test(new Hashtable(), 10);
    test(new HashMap(), 10);
    test(new TreeMap(), 10);
    // Medium:
    test(new Hashtable(), 100);
    test(new HashMap(), 100);
    test(new TreeMap(), 100);
    // Large:
    test(new HashMap(), 1000);
    test(new Hashtable(), 1000);
    test(new TreeMap(), 1000);
  
public static voidtest(java.util.Map m, int size)

         
    // A trick to print out the class name:
    System.out.println("Testing " + 
      m.getClass().getName() + " size " + size);
    fill(m, size);
    for(int i = 0; i < tests.length; i++) {
      System.out.print(tests[i].name);
      long t1 = System.currentTimeMillis();
      tests[i].test(m, size);
      long t2 = System.currentTimeMillis();
      System.out.println(": " + 
        ((double)(t2 - t1)/(double)size));
    }