Methods Summary |
---|
public static void | main(java.lang.String[] args)
int SIZE = args.length>0 ? Integer.parseInt(args[0]) : 100000;
ArrayList arrayList = new ArrayList(SIZE);
LinkedList linkedList = new LinkedList();
RandomAccessTest r;
for (int i = 0; i < SIZE; i++)
{
arrayList.add(r = new RandomAccessTest(i));
linkedList.add(r);
}
testAll(arrayList, linkedList);
|
public static void | testAll(java.util.List list1, java.util.List list2)
testLoopCounter(list1);
System.out.println("testLoopCounter(" + list2.getClass().getName() + ") not run as it takes too long");
//testLoopCounter(list2);
testIterator(list1);
testIterator(list2);
testIteratorWithLoopCounter(list1);
testIteratorWithLoopCounter(list2);
testRandomAccess(list1);
testRandomAccess(list2);
|
public static long | testIterator(java.util.List list)
long time = System.currentTimeMillis();
int count = 0;
for (Iterator i=list.iterator(); i.hasNext(); )
count += ( (RandomAccessTest) i.next()).i;
time = System.currentTimeMillis() - time;
System.out.println(list.getClass().getName() + " in testIterator took " + time + " millis to get result " + count);
return time;
|
public static long | testIteratorWithLoopCounter(java.util.List list)
long time = System.currentTimeMillis();
int count = 0;
Iterator i=list.iterator();
for (int j=0, n=list.size() ; j < n ; j++)
count += ( (RandomAccessTest) i.next()).i;
time = System.currentTimeMillis() - time;
System.out.println(list.getClass().getName() + " in testIteratorWithLoopCounter took " + time + " millis to get result " + count);
return time;
|
public static long | testLoopCounter(java.util.List list)
long time = System.currentTimeMillis();
int count = 0;
for (int i=0, n=list.size(); i < n; i++)
count += ( (RandomAccessTest) list.get(i)).i;
time = System.currentTimeMillis() - time;
System.out.println(list.getClass().getName() + " in testLoopCounter took " + time + " millis to get result " + count);
return time;
|
public static long | testRandomAccess(java.util.List list)
if (list instanceof RandomAccess)
return testLoopCounter(list);
else
return testIteratorWithLoopCounter(list);
|