I am trying to use GapList instead of ArrayList for the simple operation of adding a complex object. I see that arraylist is faster than GapList. Please see my code below. I have lot of instances of using these kind of things. Is there anyways that i could make this project faster.
GapList gapList = new GapList();
gapList.ensureCapacity(9000);
ComplexObject obj=null;
long before = System.currentTimeMillis();
//System.out.println(System.currentTimeMillis());
for(int i=0;i<90000;i++){
obj = new ComplexObject(i, "String1", new Double(i), new ArrayList(), null);
gapList.addLast(obj);
}
long afterAdd =System.currentTimeMillis();
System.out.println("Difference Gap List after add"+(afterAdd-before));
for(int i=0;i<90000;i++){
gapList.getLast();
}
long after =System.currentTimeMillis();
System.out.println("Difference Gap List after remove "+(after-afterAdd));
System.out.println("----------------------------------------------------------");
List arrayList = new ArrayList();
before = System.currentTimeMillis();
for(int i=0;i<90000;i++){
// double j=Math.random();
obj = new ComplexObject(i, "String1", new Double(i), new ArrayList(), null);
arrayList.add(obj);
}
afterAdd =System.currentTimeMillis();
System.out.println("Difference Gap List after add"+(afterAdd-before));
for(int i=0;i<90000;i++){
arrayList.get(i);
}
//
after =System.currentTimeMillis();
System.out.println("Difference Array List aftre remove"+(after-afterAdd));