Skip to content

Instantly share code, notes, and snippets.

@jonasurbano
Created April 1, 2016 13:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonasurbano/44bd0beb345c684cc4dede492cdc029c to your computer and use it in GitHub Desktop.
Save jonasurbano/44bd0beb345c684cc4dede492cdc029c to your computer and use it in GitHub Desktop.
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