Reputation: 701
I have a class which gets data from data base and sends to UI to generate charts.
The execution time of the class is 14 seconds
List listOfCLI =new ArrayList();
List listOfRRV =new ArrayList();
List listOfROP =new ArrayList();
List listOfACR =new ArrayList();
List listOfPIN =new ArrayList();
List listOfRIS =new ArrayList();
List listOfTAA =new ArrayList();
List listOfTAR =new ArrayList();
List listOfPHA =new ArrayList();
List listOfSAR =new ArrayList();
List listOfGRQ =new ArrayList();
List listOfADC =new ArrayList();
When i change the code to
List<DataMS> listOfCLI =new ArrayList<DataMS>();
List<DataMS> listOfRRV =new ArrayList<DataMS>();
List<DataMS> listOfROP =new ArrayList<DataMS>();
List<DataMS> listOfACR =new ArrayList<DataMS>();
List<DataMS> listOfPIN =new ArrayList<DataMS>();
List<DataMS> listOfRIS =new ArrayList<DataMS>();
List<DataMS> listOfTAA =new ArrayList<DataMS>();
List<DataMS> listOfTAR =new ArrayList<DataMS>();
List<DataMS> listOfPHA =new ArrayList<DataMS>();
List<DataMS> listOfSAR =new ArrayList<DataMS>();
List<DataMS> listOfGRQ =new ArrayList<DataMS>();
List<DataMS> listOfADC =new ArrayList<DataMS>();
the execution time goes up to 17 seconds.. Why did addition of the Generic suggested by eclipse has such an adverse impact.
Also can you suggest the optimal way of using Generics to reduce the execution time
**Map<String, List> reqCLI =new HashMap<String, List>();
Map<String, List> reqRRV =new HashMap<String, List>();
Map<String, List> reqROP =new HashMap<String, List>();
Map<String, List> reqACR =new HashMap<String, List>();
Map<String, List> reqPIN =new HashMap<String, List>();
Map<String, List> reqTAA =new HashMap<String, List>();
Map<String, List> reqTAR =new HashMap<String, List>();
Map<String, List> reqRIS =new HashMap<String, List>();
Map<String, List> reqPHA =new HashMap<String, List>();
Map<String, List> reqSAR =new HashMap<String, List>();
Map<String, List> reqGRQ =new HashMap<String, List>();
Map<String, List> reqADC =new HashMap<String, List>();
List<Map<String, List>> listCLI=new ArrayList<Map<String, List>>();
List<Map<String, List>> listRRV=new ArrayList<Map<String, List>>();
List<Map<String, List>> listROP=new ArrayList<Map<String, List>>();
List<Map<String, List>> listACR=new ArrayList<Map<String, List>>();
List<Map<String, List>> listPIN=new ArrayList<Map<String, List>>();
List<Map<String, List>> listTAA=new ArrayList<Map<String, List>>();
List<Map<String, List>> listTAR=new ArrayList<Map<String, List>>();
List<Map<String, List>> listRIS=new ArrayList<Map<String, List>>();
List<Map<String, List>> listPHA=new ArrayList<Map<String, List>>();
List<Map<String, List>> listSAR=new ArrayList<Map<String, List>>();
List<Map<String, List>> listGRQ=new ArrayList<Map<String, List>>();
List<Map<String, List>> listADC=new ArrayList<Map<String, List>>();**
these are the remaining collection's used
Upvotes: 1
Views: 131
Reputation: 120516
The only difference is that the java compiler can insert implicit casts:
List a = new ArrayList();
b.add("foo");
List b = new ArrayList();
for (Object o : a) {
b.add(o); // Adding an object.
}
has no casts, but there are implicit casts in
List<String> a = new ArrayList<String>();
b.add("foo");
List<String> b = new ArrayList<String>();
// Each element is implicitly cast to a String which requires
// a runtime type check.
for (String s : a) {
b.add(s);
}
That's the only difference at the byte-code level.
It's hard to tell whether that would account for the discrepancy you're seeing without knowing the number of writes and reads that you're doing but RTTI checks are pretty cheap.
Preferring batch operations like List.addAll
and Map.putAll
instead of looping should eliminate that overhead if that is the culprit.
Upvotes: 2
Reputation: 1511
Because of type erasure (see http://www.angelikalanger.com/GenericsFAQ/FAQSections/TechnicalDetails.html#FAQ101), generic types are not represented in the compiled bytecode, so there should be no difference in performance at execution time. The parameterized types are checked solely at compile time.
Upvotes: 2