Mercurial > hg > gc-bench
view src/main/java/org/openjdk/gcbench/retain/HashMaps.java @ 68:10a7f1362479
retain.HashMap: make sure it has distinct key/value pairs.
author | shade |
---|---|
date | Thu, 26 Jan 2017 15:55:45 +0100 |
parents | 12d486b68158 |
children | 583fef4276f5 |
line wrap: on
line source
package org.openjdk.gcbench.retain; import org.openjdk.jmh.annotations.*; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.concurrent.TimeUnit; @Warmup(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS) @Measurement(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS) @Fork(1) @BenchmarkMode(Mode.AverageTime) @OutputTimeUnit(TimeUnit.NANOSECONDS) @Threads(Threads.MAX) @State(Scope.Benchmark) public class HashMaps { Object retain; @Param({"100000"}) private int size; @Setup public void setup() { HashMap<Object, Object> map = new HashMap<>(); for (int c = 0; c < size; c++) { Object k = new Object(); Object v = new Object(); map.put(k, v); } retain = map; } @Benchmark public Object test() { // allocation pressure to trigger GCs return new Object(); } }