FileDocCategorySizeDatePackage
Magnitudes.javaAPI DocExample1570Tue Sep 07 18:45:40 BST 1999tuning.sorting

Magnitudes

public class Magnitudes extends Object

Fields Summary
Constructors Summary
Methods Summary
public static java.lang.Objectaccess(java.lang.Integer[] arr, java.lang.Integer in, java.lang.Object[] os)

    for (int i = arr.length-1; i >= 0; i--)
    {
      if (arr[i].equals(in))
        return os[i];
    }
    System.out.println("Warning: no element found");
    return null;
  
public static voidmain(java.lang.String[] args)

    int SIZE = 10;
    for (int i = SIZE; i < 1000 ; i+=SIZE)
      test(i, 1000);
    SIZE = 1000;
    for (int i = SIZE; ; i+=SIZE)
      test(i,1);
  
public static voidtest(int SIZE, int repeat)

    System.out.println("SIZE = " + SIZE);
    Object o = new Object();
    Object[] os = new Object[SIZE];
    HashMap hash = new HashMap();
    Integer[] arr = new Integer[SIZE];
    Integer in;
    for (int i = 0; i < SIZE; i++)
    {
      in = new Integer(i);
      hash.put(in, o);
      arr[i] = in;
    }
    long time;

    time = System.currentTimeMillis();
  for (int i = 0; i < SIZE; i++)
    for (int j = repeat; j > 0 ; j--)
    {
      in = new Integer(i);
      os[i] = hash.get(in);
    }
    time = System.currentTimeMillis() - time;
    System.out.println("Hash accessed in " + (time));

    time = System.currentTimeMillis();
  for (int i = 0; i < SIZE; i++)
    for (int j = repeat; j > 0 ; j--)
    {
      in = new Integer(i);
      os[i] = access(arr, in, os);
    }
    time = System.currentTimeMillis() - time;
    System.out.println("array accessed in " + (time));