Sunday, 26 June 2016

JIT Fun Part 1: Quick JIT visualisation of tiered compliation

See the following code:
public static void main(String... args) {
int count = 0;
for (int i =0; i <1000; i++) {
long startTime = System.nanoTime();
for (int j = 0; j < 1000; j ++) {
count += j;
}
long endtime = System.nanoTime();
System.out.printf("%d\n", endtime - startTime);
}
System.out.println(count);
}
It's not doing anything exciting, just running the same inner loop 1000 times.

I have taken those times and put them in a file called 'output.txt'.

See the following python function which reads in the numbers from output.txt and plots them on a graph:

import matplotlib.pyplot as plt
ys = []
with open('output.txt') as fp:
content = fp.readlines()
for line in content:
ys.append(int(line.strip()))
plt.plot(ys)
plt.ylabel("Time (ns)")
plt.show()
view raw plotOnGraph.py hosted with ❤ by GitHub
Here is the graph that it produces:



At first the code is running in the interperter, then the C1 JIT, then it settles into the C2 JIT. A couple of spikes probably indicate GC.




No comments:

Post a Comment

Scala with Cats: Answers to revision questions

I'm studying the 'Scala with Cats' book. I want the information to stick so I am applying a technique from 'Ultralearning...