Created
June 18, 2018 03:59
-
-
Save kyonmm/efdd711d1f602bbbe6289d1c92571552 to your computer and use it in GitHub Desktop.
groovyc Example.groovy && java -cp "groovy-all-2.4.13.jar;." Example
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.ConcurrentHashMap | |
def a = new ConcurrentHashMap(); | |
for (int i = 0; i < 1000000; i++) { | |
a.put(UUID.randomUUID().toString(), UUID.randomUUID().toString()) | |
} | |
println ((Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / (1024 * 1024)) | |
def t = new Thread(new Runnable() { | |
@Override | |
void run() { | |
def rs = a.keySet().collect{ | |
def s = System.currentTimeMillis() | |
a.get(it) | |
def e = System.currentTimeMillis() | |
e - s | |
} | |
println "finish ${rs.size()}" | |
println "${rs.min()} - ${rs.max()} - ${rs.sort().get((int)Math.floor(rs.size() / 99))}" | |
} | |
}) | |
t.start() | |
for (int i = 0; i < 10000; i++) { | |
print "-" | |
a.put(UUID.randomUUID().toString(), UUID.randomUUID().toString()) | |
} | |
println ((Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / (1024 * 1024)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment