FileDocCategorySizeDatePackage
Compare2.javaAPI DocExample4896Fri Aug 06 18:22:04 BST 1999tuning.string

Compare2

public class Compare2 extends Object

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

    try
    {

      Dict.initialize(true);
      int REPEAT = 1000;
      int count = 0;

      Object n = null;
      if (n instanceof Object)
        System.out.println("yes");
      else
        System.out.println("no");


      for(int i = Dict.DICT.length-1; i >= 0; i--)
        if (Dict.DICT[i].equals("outfox"))
            count=i;

      String[] ODICT = new String[Dict.DICT.length];
      String[] ODICT2 = new String[Dict.DICT.length];
      String[] ODICT3 = new String[Dict.DICT.length];
      String[] ODICT4 = new String[Dict.DICT.length];
      String[] ODICT5 = Dict.DICT;
      String[] ODICT6 = new String[Dict.DICT.length];
      String[] ODICT7 = new String[Dict.DICT.length];
      String[] ODICT8 = new String[Dict.DICT.length];
      String[] ODICT9 = new String[Dict.DICT.length];
      for(int i = Dict.DICT.length-1; i >= 0; i--)
      {
        ODICT[i] = Dict.DICT[count];
        ODICT2[i] = "outfo";
        ODICT3[i] = "outfox";
        ODICT4[i] = "butfox";
        ODICT6[i] = "outfoy";
        ODICT7[i] = Dict.DICT[i];
	ODICT8[i] = i + "ello";
        ODICT9[i] = Dict.DICT[i].intern();
      }

      long time = System.currentTimeMillis();
      for(int j = 100; j > 0; j--)
        for(int i = Dict.DICT.length-1; i >= 0; i--)
          if (Dict.DICT[i].equals("outfox"))
            count=i;
      time = System.currentTimeMillis() - time;
      System.out.println("time (millis) = " + time);

      count = 0;
      for(int i = Dict.DICT.length-1; i >= 0; i--)
        if (Dict.DICT[i].length() != 6)
          count++;
      System.out.println( (count*100/Dict.DICT.length) + "% of words with a different length");
      count = 0;
      for(int i = Dict.DICT.length-1; i >= 0; i--)
        if ( (Dict.DICT[i].length() == 6) && (Dict.DICT[i].charAt(0) != 'o"))
          count++;
      System.out.println( (count*100/Dict.DICT.length) + "% of words with a same length but different first char");
      count = 0;
      for(int i = Dict.DICT.length-1; i >= 0; i--)
        if ( (Dict.DICT[i].length() == 6) && (Dict.DICT[i].charAt(0) == 'o"))
          count++;
      System.out.println( (count*100/Dict.DICT.length) + "% of words with a same length and same first char");

      System.out.println("Finished initializing");

      time = System.currentTimeMillis();
      count = 0;
      String outfox = "outfox".intern();
      for(int j = REPEAT; j > 0; j--)
        for(int i = ODICT9.length-1; i >= 0; i--)
          if (outfox == ODICT9[i])
            count++;
      time = System.currentTimeMillis() - time;
      System.out.println("time (millis) = " + time + " matching " + count);

      test(ODICT3, REPEAT, " (identity " + (ODICT3[0]=="outfox") + ")");
      test(ODICT2, REPEAT, " (all different sized strings)");
      test(ODICT4, REPEAT, " (same sized strings, different first char)");
      test(ODICT6, REPEAT, " (same sized strings, different last char)");
      test(ODICT5, REPEAT, " (all different words)");
      test(ODICT, REPEAT, " (same string, not identical)");
      test(Dict.DICT, REPEAT, " (all different words)");
      test(ODICT7, REPEAT, " (all different words)");
      test(ODICT8, REPEAT, " (all different generated words)");




    }
    catch(Exception e){e.printStackTrace();}
  
public static inttest(java.lang.String[] dict, int repeat, java.lang.String s)

      long time = System.currentTimeMillis();
      int count = 0;
      for(int j = repeat; j > 0; j--)
        for(int i = dict.length-1; i >= 0; i--)
          if ("outfox".equals(dict[i]))
            count++;
      time = System.currentTimeMillis() - time;
      System.out.println("time (millis) = " + time + s);

      time = System.currentTimeMillis();
      count = 0;
      for(int j = repeat; j > 0; j--)
        for(int i = dict.length-1; i >= 0; i--)
          if (dict[i].equals("outfox"))
            count++;
      time = System.currentTimeMillis() - time;
      System.out.println("time (millis) = " + time + s);

      time = System.currentTimeMillis();
      count = 0;
      for(int j = repeat; j > 0; j--)
        for(int i = dict.length-1; i >= 0; i--)
          if ("outfox".equalsIgnoreCase(dict[i]))
            count++;
      time = System.currentTimeMillis() - time;
      System.out.println("time (millis) = " + time + s);

      time = System.currentTimeMillis();
      count = 0;
      for(int j = repeat; j > 0; j--)
        for(int i = dict.length-1; i >= 0; i--)
          if (dict[i].equalsIgnoreCase("outfox"))
            count++;
      time = System.currentTimeMillis() - time;
      System.out.println("time (millis) = " + time + s);

      return count;