We know that object size depends on its field type. But does object instantiation time depend on its fields type? See my test
public class Test {
byte f1;
byte f2;
byte f3;
byte f4;
byte f5;
byte f6;
byte f7;
byte f8;
byte f9;
byte f10;
public static void main(String[] args) {
int n = 1000000;
Test[] a = new Test[n];
long t0 = System.currentTimeMillis();
for(int i = 0; i < n; i++) {
a[i] = new Test();
}
System.out.println(System.currentTimeMillis() - t0);
}
}
Maybe not first class, still gives me rather stable results for different field types:
byte - 125 ms
int - 250 ms
long - 370 ms
Why is that? I ran it from Eclipse on my notebook (Celeron 925), it needs -Xmx1024M.