Skip to content

Instantly share code, notes, and snippets.

@talgol
Created February 23, 2021 22:22
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 talgol/14a5755db1ac83f4f6c04d71ad57c2e3 to your computer and use it in GitHub Desktop.
Save talgol/14a5755db1ac83f4f6c04d71ad57c2e3 to your computer and use it in GitHub Desktop.
A program that makes many memory allocation - for measuring the ratio of local/remote memory
public class NUMABenchmarkService {
private static final long TIME_TO_RUN = 3600000 * 12;
private static final int NUM_OF_THREADS = 1;
private final ExecutorService executorService;
class MemoryTest implements Runnable {
@Override
public void run() {
long timeToStop = System.currentTimeMillis() + TIME_TO_RUN;
int sum = 0;
while(System.currentTimeMillis() < timeToStop) {
final byte[][] arrays = new byte[1_000_000][];
for (int i = 0; i < arrays.length; i++) {
arrays[i] = new byte[1000];
ThreadLocalRandom.current().nextBytes(arrays[i]);
}
for (long l = 0; l < 1_000_000_000L; l++) {
final byte[] array = arrays[ThreadLocalRandom.current().nextInt(arrays.length)];
sum += array[ThreadLocalRandom.current().nextInt(array.length)];
}
writeThreadMetrics();
}
System.out.println(sum);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment