Skip to content

Instantly share code, notes, and snippets.

@kyonmm
Created June 18, 2018 03:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kyonmm/efdd711d1f602bbbe6289d1c92571552 to your computer and use it in GitHub Desktop.
Save kyonmm/efdd711d1f602bbbe6289d1c92571552 to your computer and use it in GitHub Desktop.
groovyc Example.groovy && java -cp "groovy-all-2.4.13.jar;." Example
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