I tried to measure execution time of primitive data types and their wrapper class for counting same number. I got that wrapper class is taking more time than primitive data types.
Execution time of primitive t1=5 and Execution time of wrapper class t2= 31 in my following code.
import java.io.*;
import java.util.*;
public class Performance
{
public static long primitive(int count)
{
long startTime = System.currentTimeMillis();
for(int i=0;i<10000;i++)
count++;
System.out.println(count);
long stopTime = System.currentTimeMillis();
long elapsedTime = stopTime - startTime;
return elapsedTime;
}
public static long wrapper(Integer count)
{
long startTime = System.currentTimeMillis();
for(int i=0;i<10000;i++)
count++;
System.out.println(count);
long stopTime = System.currentTimeMillis();
long elapsedTime = stopTime - startTime;
return elapsedTime;
}
public static void main(String args[])
{
Integer c = new Integer(0);
long t2=Performance.wrapper(c);
int count=0;
long t1=Performance.primitive(count);
System.out.println("t1="+t1+"t2="+t2);
}
}
Is there performance difference due to object creation of Wrapper class (Integer) or anything else ?