import java.util.Hashtable;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.TreeMap;
public class Test {
final static int LOOP_COUNT = 1000;
final static String STR_DATA = "abcdefghijklmnopqrstuvwxyz";
static Map<Integer, String> map;
public static void main(String[] args) {
warmUp();
map = new Hashtable<Integer, String>();
showUsedTime();
map = new HashMap<Integer, String>();
showUsedTime();
map = new LinkedHashMap<Integer, String>();
showUsedTime();
map = new TreeMap<Integer, String>();
showUsedTime();
}
private static void warmUp() {
map = new HashMap<Integer, String>();
for (int i = 0; i < LOOP_COUNT; i++) {
map.put(i, STR_DATA);
}
}
private static void showUsedTime() {
long startTime = System.nanoTime();
for (int i = 0; i < LOOP_COUNT; i++) {
map.put(i, STR_DATA);
}
long endTime = System.nanoTime();
double elaspedTime = (endTime - startTime) / 1000000.0;
System.out.println("Put Time: " + elaspedTime);
startTime = System.nanoTime();
for (int i = 0; i < LOOP_COUNT; i++) {
map.get(i);
}
endTime = System.nanoTime();
elaspedTime = (endTime - startTime) / 1000000.0;
System.out.println("Get Time: " + elaspedTime);
}
}
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.