Created
July 18, 2012 13:42
-
-
Save jlandure/3136278 to your computer and use it in GitHub Desktop.
TestPerfGuavaCache.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.concurrent.TimeUnit; | |
import org.perf4j.StopWatch; | |
import com.google.common.cache.Cache; | |
import com.google.common.cache.CacheBuilder; | |
public class TestPerfGuavaCache { | |
public static final String KEY = "KEY"; | |
public static final String VALUE = "VALUE"; | |
public static void main(String[] args) throws Exception { | |
StopWatch stopWatch = new StopWatch(); | |
Cache<String, String> maps = CacheBuilder.newBuilder()// | |
// .maximumSize(1000)// | |
.expireAfterWrite(10, TimeUnit.MINUTES)// | |
.build(); | |
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.getIfPresent(key)); | |
// set a new object | |
maps.put(key, value); | |
System.out.println("set Object in memory :"); | |
System.out.println("Get Object after set :" + maps.getIfPresent(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