|
Java example source code file (IntObjectHashMapBenchmark.java)
The IntObjectHashMapBenchmark.java Java example source code/* * Copyright 2015 The Netty Project * * The Netty Project licenses this file to you under the Apache License, version 2.0 (the * "License"); you may not use this file except in compliance with the License. You may obtain a * copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software distributed under the License * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express * or implied. See the License for the specific language governing permissions and limitations under * the License. */ package io.netty.microbenchmark.common; import io.netty.microbench.util.AbstractMicrobenchmark; import io.netty.util.collection.IntObjectHashMap; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.BenchmarkMode; import org.openjdk.jmh.annotations.Level; import org.openjdk.jmh.annotations.Mode; import org.openjdk.jmh.annotations.Param; import org.openjdk.jmh.annotations.Setup; import org.openjdk.jmh.infra.Blackhole; import uk.co.real_logic.agrona.collections.Int2ObjectHashMap; import java.util.HashSet; import java.util.Random; import java.util.Set; public class IntObjectHashMapBenchmark extends AbstractMicrobenchmark { private static final Long VALUE = Long.MAX_VALUE; public enum MapType { AGRONA, NETTY } public enum KeyDistribution { HTTP2, RANDOM } @Param({ "10", "100", "1000", "10000", "100000" }) public int size; @Param public MapType mapType; @Param public KeyDistribution keyDistribution; private Environment environment; @Setup(Level.Trial) public void setup() { switch(mapType) { case AGRONA: { environment = new AgronaEnvironment(); break; } case NETTY: { environment = new NettyEnvironment(); break; } default: { throw new IllegalStateException("Invalid mapType: " + mapType); } } } @Benchmark @BenchmarkMode(Mode.Throughput) public void put(Blackhole bh) { environment.put(bh); } @Benchmark @BenchmarkMode(Mode.Throughput) public void lookup(Blackhole bh) { environment.lookup(bh); } @Benchmark @BenchmarkMode(Mode.Throughput) public void remove(Blackhole bh) { environment.remove(bh); } private abstract class Environment { final int[] keys; Environment() { keys = new int[size]; switch(keyDistribution) { case HTTP2: for (int index = 0, key = 3; index < size; ++index, key += 2) { keys[index] = key; } break; case RANDOM: { // Create a 'size' # of random integers. Random r = new Random(); Set<Integer> keySet = new HashSet Other Java examples (source code examples)Here is a short list of links related to this Java IntObjectHashMapBenchmark.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.