-
-
Save jonasurbano/44bd0beb345c684cc4dede492cdc029c to your computer and use it in GitHub Desktop.
This file contains 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 GCing { | |
private static final int k = 1024; | |
private static final int m = k * k; | |
private static final int MAX_ITERATIONS = 10; | |
private static final int DEFAULT_SIZE = 640; | |
private static int iterations = 1; | |
private byte[] bytes; | |
public static void main(String[] args) throws InterruptedException { | |
int size = sizeFromArgumentsOrDefault(args); | |
System.err.println("Size is " + size + " MB"); | |
while (condition()) { | |
process(size); | |
} | |
} | |
private static void process(int size) { | |
long milis = System.currentTimeMillis(); | |
GCing gcing1 = new GCing(size * m); | |
System.err.println("Milis: " + (System.currentTimeMillis() - milis)); | |
} | |
private static boolean condition() { | |
return iterations++ <= MAX_ITERATIONS; | |
} | |
private static int sizeFromArgumentsOrDefault(String[] args) { | |
if (args == null || args.length == 0) | |
return DEFAULT_SIZE; | |
int size = DEFAULT_SIZE; | |
try { | |
size = Integer.parseInt(args[0]); | |
} catch (Exception exception) { | |
} | |
if (size < 0) | |
return DEFAULT_SIZE; | |
return size; | |
} | |
public GCing(int size) { | |
bytes = new byte[size]; | |
} | |
public byte[] getBytes() { | |
return bytes; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment