FileDocCategorySizeDatePackage
SpecialKeyClass.javaAPI DocExample2370Thu Jul 11 19:12:14 BST 2002tuning.hash

SpecialKeyClass

public class SpecialKeyClass extends Object

Fields Summary
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)

    maintest(args);
    if (args.length > 0)
      maintest(args);
  
public static voidmaintest(java.lang.String[] args)

    int REPEAT = 50;
    //Initialize the dictionary
    try{Dict.initialize(true);}catch(Exception e){}
    System.out.println("Started Test");

    //Build the two hashtables. Keep references to the StringWrapper objects
    //for later use as accessors.
    Hashtable h1 = new Hashtable();
    Hashtable h2 = new Hashtable();
    StringWrapper[] dict = new StringWrapper[Dict.DICT.length];
    for (int i = 0; i < Dict.DICT.length; i++)
    {
      h1.put(Dict.DICT[i], Boolean.TRUE);
      h2.put(dict[i] = new StringWrapper(Dict.DICT[i]), Boolean.TRUE);
    }
    System.out.println("Finished building");

    Object[] o = new Object[Dict.DICT.length];

    //Time the access for normal String keys
    long time1 = System.currentTimeMillis();
  for (int j = 0; j < REPEAT; j++)
    for (int i = 0; i < Dict.DICT.length; i++)
      o[i] = h1.get(Dict.DICT[i]);
    time1 = System.currentTimeMillis() - time1;
    System.out.println("Time1 = " + time1);

    //Time the access for StringWrapper keys
    long time2 = System.currentTimeMillis();
  for (int j = 0; j < REPEAT; j++)
    for (int i = 0; i < Dict.DICT.length; i++)
      o[i] = h2.get(dict[i]);
    time2 = System.currentTimeMillis() - time2;
    System.out.println("Time2 = " + time2);