-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTimingTests.java
62 lines (51 loc) · 1.57 KB
/
TimingTests.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
Sami Badra
CS 310, Spring 2014
Assignment #3, red-black BST
FILE: TimingTests.java
Copyright (c) 2015 Sami Badra. All rights reserved.
*/
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
import RedBlackTree;
public class TimingTests {
public static void main(String[] args) throws FileNotFoundException{
RedBlackTree<Word> Tree = new RedBlackTree();
File file = new File("textFile");
Scanner fileScanner = new Scanner(file);
String s;
long start = System.currentTimeMillis();
while (fileScanner.hasNext()) {
s = fileScanner.next();
Tree.add(new Word(s));
}
long stop = System.currentTimeMillis();
Word a = new Word("assessment");
Word b = new Word("central");
Word c = new Word("helped");
Word d = new Word("influence");
Word e = new Word("manager");
Word f = new Word("official");
Word g = new Word("radically");
Word h = new Word("throws");
Word i = new Word("website");
Word j = new Word("yearning");
long findStart = System.nanoTime();
Tree.find(a);
Tree.find(b);
Tree.find(c);
Tree.find(d);
Tree.find(e);
Tree.find(f);
Tree.find(g);
Tree.find(h);
Tree.find(i);
Tree.find(a);
long findStop = System.nanoTime();
long total = stop - start;
long findAverage = (findStop - findStart) / 10000;
System.out.println("The Red-Black Tree took " + total + " milliseconds to add " + Tree.size() + " words to the tree.");
System.out.println("The Red-Black Tree took an average of " + findAverage + " microseconds (per word) to find 10 random words in the tree.");
}
}