import static org.junit.Assert.assertEquals; import java.util.Iterator; import java.util.Random; import org.junit.Test; public class PerformanceTesting { // @Test public void testingCool(){ BinarySearchTree b = new BinarySearchTree<>(); int size = 1048576; int halfSize = (size/2)-100; int v = size / 2; int temp; while (v > 0) { temp = v; while (temp < size){ b.insert(temp); temp += v; } v = v / 2; } System.out.println(b.size()); System.out.println(b.height()); System.out.println(b.potential()); } @Test public void testingNewOverAllPerformancePosted(){ BinarySearchTree t = new BinarySearchTree<>(); int nums = 2000000; int[] a = new int[nums]; // populating array for (int i = 0; i < nums; i++){ a[i] = i; } int i1; int i2; int temp; // shuffling array for (int i = 0; i < nums; i++) { i1 = (int) (Math.random() * nums); i2 = (int) (Math.random() * nums); temp = a[i1]; a[i1] = a[i2]; a[i2] = temp; } // priming the tree: inserting half of the array into the tree int numHalf = nums/2; for (int i = 0; i < numHalf; i++) t.insert(a[i]); // t.resetRotationCount(); // t.resetDoubleRotationCount(); // timing data: inserting the remaining half of the array into the tree long startTime = System.currentTimeMillis(); for (int i = numHalf; i < nums; i++) t.insert(a[i]); long endTime = System.currentTimeMillis(); System.out.println("Inserting " + numHalf + " elements took: " + (endTime - startTime) + " milliseconds"); System.out.println("The corresponding height is: " + t.height()); System.out.println("Potential of tree with " + nums + " elements is: " + t.potential()); // System.out.println("Rotations on inserting " + numHalf + " elements: " + (t.getRotationCount() - t.getDoubleRotationCount())); Iterator it; Random r = new Random(); int max = 0; startTime = System.currentTimeMillis(); for (int i = 0; i < numHalf; i++) { it = t.iterator(); max = 5 + r.nextInt(96); for (int k = 0; k < max; k++) { it.next(); } } endTime = System.currentTimeMillis(); System.out.println("Returning top-5-100 1Mio times in 2Mio tree: " + (endTime - startTime) + " milliseconds"); a = new int[nums]; // populating array for (int i = 0; i < numHalf; i++){ a[i] = (int)(Math.random()*nums); } startTime = System.currentTimeMillis(); for (int i = 1; i < numHalf; i++){ t.find(a[i]); } endTime = System.currentTimeMillis(); System.out.println("Finding " + numHalf + " elements in tree with " + numHalf + " elements took: " + (endTime - startTime) + " milliseconds"); a = new int[nums]; // populating array for (int i = 0; i < nums; i++){ a[i] = i; } // shuffling array for (int i = 0; i < nums; i++) { i1 = (int) (Math.random() * nums); i2 = (int) (Math.random() * nums); temp = a[i1]; a[i1] = a[i2]; a[i2] = temp; } // t.resetRotationCount(); // t.resetDoubleRotationCount(); startTime = System.currentTimeMillis(); for (int i = 1; i < numHalf; i++){ t.remove(a[i]); } endTime = System.currentTimeMillis(); System.out.println("Removing " + numHalf + " elements took: " + (endTime - startTime) + " milliseconds"); // System.out.println("Rotations on removing " + numHalf + " elements: " + (t.getRotationCount()-t.getDoubleRotationCount())); } }