How to write a code to
test the performance of class. For example I have these 2 class . Can any one give me example for this.?
---------------------------------------------
public class SlowDictionary {
private final Map<
String, String> dict = new HashMap<String, String>();
public synchronized String translate(String
word)
throws IllegalArgumentException {
if (!dict.containsKey(word)) {
throw new IllegalArgumentException(word + " not found.");
}
return dict.get(word);
}
public synchronized void addToDictionary(String word, String translation)
throws IllegalArgumentException {
if (dict.containsKey(word)) {
throw new IllegalArgumentException(word + " already exists.");
}
dict.put(word, translation);
}
public synchronized Set<String> getAllWords() {
return dict.keySet();
}
}
------------------------------------------------------------------------
public class WhatDoIDo{
private X x;
private boolean b;
private Object o;
public WhatDoIDo(X x) {
this.x = x;
}
synchronized Object z() {
if (!b) {
o = x.y();
b = true;
}
return o;
}
public interface X {
Object y();
}
}