I'm trying to collect data about execution time and compare the times when enqueuing and dequeuing a heap tree vs bst. For the time elapsed I use nanoTime().
Everything looks fine with the time elapsed when enqueuing/dequeuing heap trees, both unsorted and sorted. Also when enqueuing bst. When I'm trying to dequeue a sorted bst with say 700000 elements the execution takes very long. That's okey, it's similar when enqueuing a sorted bst.
The problem is that the time elapsed for execution is not correct. The time should be something about 15000 milliseconds, but I get an answer about 0,5 milliseconds (or 459053 ns).
First I'm enqueuing a bst with 640000 elements (integers), then sorting the tree. What I'm interesting in is the execution time when enqueuing this bst (with already 640000 sorted elements).
Here is my code (part of it):
public static void main(String[] args)
throws DuplicateItemException, FileNotFoundException, IOException, EmptyQueueException {
final String pathFullList = "Files/data_640000.txt";
final String pathPartialList = "Files/data_6400.txt";
final int SIZE_SEVEN = 640000;
final int SIZE_FOR_LIST_TWO = 6400;
BSTPriorityQueue<Integer> bstQueue = new BSTPriorityQueue<Integer>();
bstQueue.clear();
List<Integer> listOne = new ArrayList<Integer>();
listOne = loadList(pathFullList, SIZE_SEVEN);
Collections.sort(listOne);
long execTimeForSort = System.nanoTime() - t2;
System.out.println("Time for sort: " + execTimeForSort);
enqueueBstTree(listOne, bstQueue);
System.out.println("Size of hptree before enqueue: " + hPQueue.size() +
"\n" + "Size of bsttree before enqueue: " + bstQueue.size());
List<Integer> listTwo = new ArrayList<Integer>();
listTwo = loadList(pathPartialList, SIZE_FOR_LIST_TWO);
long t1 = System.nanoTime();
dequeueBstTree(listTwo, bstQueue, SIZE_FOR_LIST_TWO);
long execTime = System.nanoTime() - t1;
System.out.println("Time difference for enqueue/dequeue: " + execTime);
System.out.println("Size of hptree after enqueue/dequeue: " + hPQueue.size() +
"\n" + "Size of bsttree after enqueue/dequeue: " + bstQueue.size());
}
This code takes maybe 20 minutes to execute. The answer I get from execTime is 459053 nanoseconds.