FileDocCategorySizeDatePackage
Test2.javaAPI DocExample12736Tue Jul 09 16:25:16 BST 2002tuning.struct

Test2

public class Test2 extends Object

Fields Summary
Constructors Summary
Methods Summary
public static voidfulltest(tuning.struct.TestList collection, tuning.struct.TestStringList l)

    test1(collection);
    test2(collection);
    test3(collection);
    test4(collection);
    test5(collection);
    test6(collection);
    test7(collection);
    test8(collection);
    test9(collection);
    test10(collection);
    test11(collection);
    test12(l);
    test13(l);
    test14(l);
    System.out.println();
  
public static voidinitializeList(java.util.List collection)

    System.out.println("Initializing...");
    //All four character strings. Extend to more characters
    //depending on your processor speed and memory availability
    char c = 'a";
    char d = 'a";
    char e = 'a";
    char f = 'a";
    StringBuffer sb = new StringBuffer(4);
    for (int ic = 0; ic < 26; ic++)
    {
      sb.setLength(0);
      sb.append(c++);
      d = e = f = 'a";
      for (int id = 0; id < 26; id++)
      {
        sb.setLength(1);
        sb.append(d++);
        e = f = 'a";
        for (int ie = 0; ie < 26; ie++)
        {
          sb.setLength(2);
          sb.append(e++);
          f = 'a";
          for (int i = 0; i < 26; i++)
          {
            sb.setLength(3);
            sb.append(f++);
            collection.add(sb.toString());
          }
        }
      }
    }
    System.out.println("Finished initializing.");
  
public static voidmain(java.lang.String[] args)

    TestList collection = new TestList();
    initializeList(collection);
    TestStringList l = new TestStringList(collection);

    test0(collection); //ignore
    test0(l); //ignore
    System.out.println("Test0 is simply to fully initialize the runtime");
    System.out.println();

    fulltest(collection, l);
    fulltest(collection, l);
    fulltest(collection, l);
    fulltest(collection, l);
  
public static voidtest0(tuning.struct.TestStringList collection)

    int count = 0;
    for(int i = 0; i < collection.size(); i++)
    {
      if(     ( ((String) collection.get(i)).indexOf("ie") != -1 )
           | ( ((String) collection.get(i)).indexOf("xy") != -1 )
           | ( ((String) collection.get(i)).indexOf("pq") != -1 ) )
        count++;
    }
  
public static voidtest0(tuning.struct.TestList collection)

    int count = 0;
    for(int i = 0; i < collection.size()/2; i++)
    {
      if(     ( ((String) collection.get(i)).indexOf("ie") != -1 )
           | ( ((String) collection.get(i)).indexOf("xy") != -1 )
           | ( ((String) collection.get(i)).indexOf("pq") != -1 ) )
        count++;
    }
    for(int i = collection.size()/2; i < collection.size(); i++)
    {
      if(     ( ((String) collection.getAsArrayList(i)).indexOf("ie") != -1 )
           | ( ((String) collection.getAsArrayList(i)).indexOf("xy") != -1 )
           | ( ((String) collection.getAsArrayList(i)).indexOf("pq") != -1 ) )
        count++;
    }
    System.out.println("Test0 completed");
  
public static voidtest1(tuning.struct.TestList collection)

    //Initial test
    long time = System.currentTimeMillis();
    int count = 0;
    for(int i = 0; i < collection.size(); i++)
    {
      if(     ( ((String) collection.get(i)).indexOf("ie") != -1 )
           | ( ((String) collection.get(i)).indexOf("xy") != -1 )
           | ( ((String) collection.get(i)).indexOf("pq") != -1 ) )
        count++;
    }
    System.out.println("Test1: initial test.                          Time is " + 
      (System.currentTimeMillis()-time) + " (result " + count + " elmnts)");
  
public static voidtest10(tuning.struct.TestList collection)

    long time = System.currentTimeMillis();
    int count = collection.customQuery2();
    System.out.println("Test10: using optimized customQuery2.         Time is " + 
      (System.currentTimeMillis()-time) + " (result " + count + " elmnts)");
  
public static voidtest11(tuning.struct.TestList collection)

    long time = System.currentTimeMillis();
    int count = collection.customQuery3();
    System.out.println("Test11: using optimized customQuery3.         Time is " + 
      (System.currentTimeMillis()-time) + " (result " + count + " elmnts)");
  
public static voidtest12(tuning.struct.TestStringList l)

    long time = System.currentTimeMillis();
    int count = l.customQuery1();
    System.out.println("Test12: using String optimized customQuery1.  Time is " + 
      (System.currentTimeMillis()-time) + " (result " + count + " elmnts)");
  
public static voidtest13(tuning.struct.TestStringList l)

    long time = System.currentTimeMillis();
    int count = l.customQuery2();
    System.out.println("Test13: using String optimized customQuery2.  Time is " + 
      (System.currentTimeMillis()-time) + " (result " + count + " elmnts)");
  
public static voidtest14(tuning.struct.TestStringList l)

    long time = System.currentTimeMillis();
    int count = l.customQuery3();
    System.out.println("Test14: using String optimized customQuery3.  Time is " + 
      (System.currentTimeMillis()-time) + " (result " + count + " elmnts)");
  
public static voidtest2(tuning.struct.TestList collection)

    long time = System.currentTimeMillis();
    int count = 0;
    for(int i = 0; i < collection.size(); i++)
    {
      if(     ( ((String) collection.get(i)).indexOf("ie") != -1 )
           || ( ((String) collection.get(i)).indexOf("xy") != -1 )
           || ( ((String) collection.get(i)).indexOf("pq") != -1 ) )
        count++;
    }
    System.out.println("Test2: changing to shortcut booleans.         Time is " + 
      (System.currentTimeMillis()-time) + " (result " + count + " elmnts)");
  
public static voidtest3(tuning.struct.TestList collection)

    long time = System.currentTimeMillis();
    int count = 0;
    int max = collection.size();
    for(int i = 0; i < max; i++)
    {
      if(     ( ((String) collection.get(i)).indexOf("ie") != -1 )
           | ( ((String) collection.get(i)).indexOf("xy") != -1 )
           | ( ((String) collection.get(i)).indexOf("pq") != -1 ) )
        count++;
    }
    System.out.println("Test3: replacing size() call with a variable. Time is " + 
      (System.currentTimeMillis()-time) + " (result " + count + " elmnts)");
  
public static voidtest4(tuning.struct.TestList collection)

    long time = System.currentTimeMillis();
    int count = 0;
    int max = collection.size();
    for(int i = 0; i < max; i++)
    {
      if(     ( ((String) collection.get(i)).indexOf("ie") != -1 )
           || ( ((String) collection.get(i)).indexOf("xy") != -1 )
           || ( ((String) collection.get(i)).indexOf("pq") != -1 ) )
        count++;
    }
    System.out.println("Test4: both test2 and test3 optimizations.    Time is " + 
      (System.currentTimeMillis()-time) + " (result " + count + " elmnts)");
  
public static voidtest5(tuning.struct.TestList collection)

    long time = System.currentTimeMillis();
    int count = 0;
    int max = collection.size();
    String s;
    for(int i = 0; i < max; i++)
    {
      if(     ( (s = (String) collection.get(i)).indexOf("ie") != -1 )
           || (                       s.indexOf("xy") != -1 )
           || (                       s.indexOf("pq") != -1 ) )
        count++;
    }
    System.out.println("Test5: as test4, plus eliminating two casts.  Time is " + 
      (System.currentTimeMillis()-time) + " (result " + count + " elmnts)");
  
public static voidtest6(tuning.struct.TestList collection)

    long time = System.currentTimeMillis();
    int count = 0;
    String s;
    for(int i = 0; i < collection.size(); i++)
    {
      if(     ( (s = (String) collection.get(i)).indexOf("ie") != -1 )
           || (                       s.indexOf("xy") != -1 )
           || (                       s.indexOf("pq") != -1 ) )
        count++;
    }
    System.out.println("Test6: as test3, plus eliminating two casts.  Time is " + 
      (System.currentTimeMillis()-time) + " (result " + count + " elmnts)");
  
public static voidtest7(tuning.struct.TestList collection)

    long time = System.currentTimeMillis();
    int count = 0;
    int max = collection.size();
    String s;
    for(int i = 0; i < max; i++)
    {
      if(     ( (s = (String) collection.getAsArrayList(i)).indexOf("ie") != -1 )
           || (                       s.indexOf("xy") != -1 )
           || (                       s.indexOf("pq") != -1 ) )
        count++;
    }
    System.out.println("Test7: as test5, but using ArrayList.get().   Time is " + 
      (System.currentTimeMillis()-time) + " (result " + count + " elmnts)");
  
public static voidtest8(tuning.struct.TestList collection)

    long time = System.currentTimeMillis();
    int count = 0;
    String s;
    for(int i = 0; i < collection.size(); i++)
    {
      if(     ( (s = (String) collection.getAsArrayList(i)).indexOf("ie") != -1 )
           || (                       s.indexOf("xy") != -1 )
           || (                       s.indexOf("pq") != -1 ) )
        count++;
    }
    System.out.println("Test8: as test6, but using ArrayList.get().   Time is " + 
      (System.currentTimeMillis()-time) + " (result " + count + " elmnts)");
  
public static voidtest9(tuning.struct.TestList collection)

    long time = System.currentTimeMillis();
    int count = collection.customQuery1();
    System.out.println("Test9: using optimized customQuery1.          Time is " + 
      (System.currentTimeMillis()-time) + " (result " + count + " elmnts)");