package iteratorVSarray;
import java.util.ArrayList;
import java.util.Iterator;
import kr.ac.kyungnam.dblab.*;
public class Test {
/**
* @param args
*/
public static void perform(Object o) {
}
public static void main(String[] args) {
/*
* First, invoke all of the Benchmark class' method.
* Because of the character of static method's which is being loaded when class is loading.
*/
Benchmark.start();
Benchmark.finish();
Benchmark.result();
/*
* Make 1000000 Integer ArrayList Object
* The index number of ArrayList al is the same as the value
*
* and check the creation Time.
*/
Benchmark.start();
ArrayList al = new ArrayList();
for(int i = 0; i < 1000000; i++) {
al.add( new Integer(i) );
}
Benchmark.finish();
System.out.println("create Sample 1000000 Arraylist Data :" + Benchmark.result() + "ms");
System.out.println();
/*
* Check Iterator creation time
*/
Benchmark.start();
Iterator it = al.iterator();
Benchmark.finish();
System.out.println("getting iterator : " + Benchmark.result() + "ms" );
Benchmark.start();
for(; it.hasNext(); )
perform(it.next());
Benchmark.finish();
System.out.println("iteration time: " + Benchmark.result()+ "ms");
System.out.println();
Benchmark.start();
for(int i = 0 ; i < al.size() ; i++) {
perform(al.get(i));
}
Benchmark.finish();
System.out.println("Arraylist's get(n) method:" + Benchmark.result() + "ms");
System.out.println();
Benchmark.start();
Integer[] iv = new Integer[al.size()];
iv = (Integer[])al.toArray(iv);
Benchmark.finish();
System.out.println("convert ArrayList type to Integer[] :" + Benchmark.result() + "ms");
Benchmark.start();
Object[] ov = al.toArray();
Benchmark.finish();
System.out.println("convert ArrayList type to Object[] :" + Benchmark.result() + "ms");
Benchmark.start();
for(int i = 0 ; i < iv.length ; i++) {
perform(iv[i]);
}
Benchmark.finish();
System.out.println("getting Integer[]'s all element:" + Benchmark.result() + "ms" );
}
}
결과

댓글 없음:
댓글 쓰기