@Benchmark public void ourGet(final Blackhole blackhole) { final Map<Integer, String> ourMap = this.ourMap; for (int index : indexes) { blackhole.consume(ourMap.get(index)); } }
@Benchmark public void defaultGet(final Blackhole blackhole) { final Map<Integer, String> defaultMap = this.defaultMap; for (int index : indexes) { blackhole.consume(defaultMap.get(index)); } }
@Benchmark public void ourPut(final Blackhole blackhole) { final Map<Integer, String> ourMap = this.ourMap; final List<Integer> indexes = this.indexes; final List<String> values = this.values; for (int i = 0, n = indexes.size(); i < n; i++) { blackhole.consume(ourMap.put(indexes.get(i), values.get(i))); } }
@Setup public void setup() { for (int i = 0; i < size; i++) { ourMap.put(i, String.valueOf(i)); defaultMap.put(i, String.valueOf(i)); } indexes = new ArrayList<>(); values = new ArrayList<>(); Random random = new Random(100); for (int i = 1; i <= 100; i++) { int index = random.nextInt(size); indexes.add(index); values.add(String.valueOf(index)); } }