I have a loop like this
int length = 1000000000;
Integer sum1 = 0;
for (Integer i = 0; i < length; i++) {
sum1 = sum1 + 1;
}
System.out.println(sum1);
How do I count the number of boxing and unboxing operations here? Here are what I guess to be boxing and unboxing
boxing:
i++
boxesi + 1
toInteger
sum1 + 1
is boxed to Integer
unboxing:
i < length
unboxesi
toint
Am I correct for above? And how can I programmatically count the number of boxing and unboxing operations?