I have the following main function:
public static void main(String[] args) {
int times = 100;
double startTime = System.nanoTime();
for (int a = 1; a <= times; a++) {
BTree<Integer> testTree = new BTree<Integer>(1,3); // Creates BTree with root 1 and degree T 3
for (int i = 2; i <= 500; i++) {
testTree.BTreeInsert(i); // We insert up to 500 keys.
}
}
double stopTime = System.nanoTime();
System.out.println("Time: " + (((stopTime-startTime) / 1000000 / times)) + "ms");
}
What I'm trying to do here is measure the execution time for inserting a new key into a B-Tree up to 500 times. The problem is the time measurement I get is somewhat small, so my teacher told me to loop it a number of times.
However, the results I'm getting don't seem to add up, with this configuration the program returns Time: 0.167(..) ms, meanwhile with times = 1 the code returns Time: 2.1401 ms.
I feel like I'm missing out on something important, but I can't figure out what.
BTreedefined as? Are you sure it has no bugs and that the compiler optimizer isn't getting in the way?timeswhen you print it out. So this is telling you that when you do this a bunch of times in a row, it's faster. This makes sense, because there is a lot of overhead in preparing the JVM