| import java.math.BigInteger; |
| * Simple test to see what is the performance difference between converting |
| * simple int values into different wrapper types. |
| public final class CheckNumberSpeed |
| final static int REPS = 2000; |
| private CheckNumberSpeed() { |
| for (int i = 0; i < data.length; ++i) { |
| // mostly small positive numbers, some negative |
| public void test() throws Exception |
| long start = System.nanoTime(); |
| o = testIntsValueOf(data); |
| o = testIntsCreate(data); |
| long time = System.nanoTime() - start; |
| time = time >> 10; // from nano to micro |
| System.out.println("Time for '"+str+"' -> "+time+" us (hash: "+o.hashCode()+")"); |
| Integer testIntsValueOf(int[] ints) |
| v = Integer.valueOf(data); |
| Integer testIntsCreate(int[] ints) |
| Long testLongs(int[] ints) |
| BigInteger testBigInts(int[] ints) |
| v = BigInteger.valueOf(data); |
| public static void main(String[] args) throws Exception |
| new CheckNumberSpeed().test(); |