Java Generic Lists and Arrays performance -
i'm wondering why performance bad when working generic lists , arrays in java.
i had below create generic array, taking on 2 seconds create array 50 elements.
final t[] returnclasses = (t[]) array.newinstance(classoft, data.getcount());
after reading number of areas java.lang.reflect.array shouldn't used hasn't been optimised , use lists instead changed code below.
list<t> returndatalist = new arraylist(data.getcount());
after change there no performance increase.
when comparing timings creating explicitly typed list times returned 0ms
what efficient way create collection (must retain order) when using generics?
if makes difference method declared as
public <t> list<t> method(data data, class<t> classoft)
logging done below code
calendar = calendar.getinstance(); list<t> returndatalist = new arraylist(data.getcount()); log.d("test", "create array time = " + (calendar.getinstance().gettimeinmillis() - now.gettimeinmillis())); = calendar.getinstance(); list<object> test = new arraylist(data.getcount()); log.d("test", "create test array time = " + (calendar.getinstance().gettimeinmillis() - now.gettimeinmillis()));
i understand form of logging isn't correct method proper performance testing, it's super simple way idea of differences between 2 basic pieces of code.
Comments
Post a Comment