Created
September 4, 2018 18:40
-
-
Save sshh12/f14a8154bb7ce5b26c4049f616139b58 to your computer and use it in GitHub Desktop.
Array Runtime Tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ArrayMaker { | |
public static void main(String[] args) { | |
int N = 150000; | |
for(int n = 500; n < N; n += 100) { | |
long sumInt = 0, sumLong = 0, sumObject = 0; | |
for(int t = 0; t < 10000; t++) { | |
sumInt += makeIntArray(n); | |
sumLong += makeLongArray(n); | |
sumObject += makeObjectArray(n); | |
} | |
System.out.printf("%d\t%d\t%d\t%d\n", n, sumInt, sumLong, sumObject); | |
} | |
} | |
public static long makeIntArray(int n) { | |
final long startTime = System.nanoTime(); | |
int[] ary = new int[n]; | |
final long endTime = System.nanoTime(); | |
return endTime - startTime; | |
} | |
public static long makeLongArray(int n) { | |
final long startTime = System.nanoTime(); | |
long[] ary = new long[n]; | |
final long endTime = System.nanoTime(); | |
return endTime - startTime; | |
} | |
public static long makeObjectArray(int n) { | |
final long startTime = System.nanoTime(); | |
Object[] ary = new Object[n]; | |
final long endTime = System.nanoTime(); | |
return endTime - startTime; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment