Skip to content

Instantly share code, notes, and snippets.

@jlandure
Created July 18, 2012 13:39
Show Gist options
  • Save jlandure/3136269 to your computer and use it in GitHub Desktop.
Save jlandure/3136269 to your computer and use it in GitHub Desktop.
TestPerfHashmap.java
import java.util.HashMap;
import javax.cache.CacheException;
import org.perf4j.StopWatch;
public class TestPerfHashmap {
public static final String KEY = "KEY";
public static final String VALUE = "VALUE";
public static void main(String[] args) throws CacheException {
StopWatch stopWatch = new StopWatch();
HashMap<String, String> maps = new HashMap<>();
for (int i = 0; i < 1_000_000; i++) {
String key = KEY + i;
String value = VALUE + i;
System.out.println("get Object in memory :" + maps.get(key));
// set a new object
System.out.println("set Object in memory :" + maps.put(key, value));
System.out.println("Get Object after set :" + maps.get(key));
}
stopWatch.stop();
System.out.println("OldFashion Elapsed Time: " + stopWatch.getElapsedTime());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment