I would like to time how long the program takes to insert in the tree to measure the efficiency of a TreeMap's inserting. I also want to measure how long it takes to sort separately. I am doing this for a report I am writing where I am comparing the inserting time and sorting time for a TreeMap, linkedList and ArrayList. For the linkedList and ArrayList I am just going to insert all and measure first, then call list.sort(comparator) and measure how long it takes to sort. I am not sure how to do this for a TreeMap though.
final long startTime = System.currentTimeMillis();
Comparator<String> secondCharComparator = new Comparator<String>() {
@Override public int compare(String s1, String s2) {
return s1.substring(1, 2).compareTo(s2.substring(1, 2));
}
};
SortedMap<String,String> map =
new TreeMap<String,String>(secondCharComparator);
map.put("a", "one");
map.put("a", "two");
map.put("cd", "three");
final long endTime = System.currentTimeMillis();
long totalTime = endTime - startTime;