Created
February 18, 2014 04:55
-
-
Save bjpeterdelacruz/9064842 to your computer and use it in GitHub Desktop.
This code snippet shows you how to warm up the JVM before performing any benchmarks.
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
private static final int NUM_ITERATIONS = 100; | |
// ... | |
System.out.println("Warming up..."); | |
for (int i = 1; i <= NUM_ITERATIONS; i++) { | |
for (Node node : nodes) { | |
Band<Float> band = createBand(Float.class); | |
Random random = new Random(); | |
statsMap.put(band, new Stats(band, random.nextInt(200), | |
random.nextFloat() * 10)); | |
} | |
Collections.sort(new ArrayList<Stats<(statsMap.values())); | |
statsMap.clear(); | |
} | |
long totalRuntime = 0; | |
System.out.println("Benchmarking..."); | |
for (int i = 1; i <= NUM_ITERATIONS; i++) { | |
for (Node node : nodes) { | |
Band<Float> band = createBand(Float.class); | |
Random random = new Random(); | |
statsMap.put(band, new Stats(band, random.nextInt(200), | |
random.nextFloat() * 10)); | |
} | |
start = System.currentTimeMillis(); | |
Collections.sort(new ArrayList<Stats>(statsMap.values())); | |
end = System.currentTimeMillis(); | |
System.out.println("Run #" + i + ": " + (end - start) + " ms"); | |
totalRuntime += (end - start); | |
statsMap.clear(); | |
} | |
double average = (totalRuntime / (double) NUM_ITERATIONS); | |
System.out.println("Average runtime: " + average + " ms"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment