Created
June 9, 2016 14:31
-
-
Save vladimirdolzhenko/e956c411f1a39e0f3e9f43b0573c1964 to your computer and use it in GitHub Desktop.
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 gnu.trove.map.hash.THashMap; | |
import org.openjdk.jmh.annotations.*; | |
import org.openjdk.jmh.infra.Blackhole; | |
import org.openjdk.jmh.runner.Runner; | |
import org.openjdk.jmh.runner.RunnerException; | |
import org.openjdk.jmh.runner.options.Options; | |
import org.openjdk.jmh.runner.options.OptionsBuilder; | |
import java.io.IOException; | |
import java.util.HashMap; | |
import java.util.concurrent.TimeUnit; | |
/** | |
* | |
* Run complete. Total time: 00:00:21 | |
* | |
* Benchmark Mode Cnt Score Error Units | |
* HashPerf.javaUtilMapStringKeyInsert avgt 5 1.872 ± 0.014 us/op | |
* HashPerf.troveMapStringKeyInsert avgt 5 2.009 ± 0.016 us/op | |
* | |
* @author yury.vasyutinskiy | |
* @since 08/06/2016 | |
*/ | |
@BenchmarkMode(Mode.AverageTime) | |
@OutputTimeUnit(TimeUnit.MICROSECONDS) | |
@Fork(1) | |
@Warmup(iterations = 5, time = 1000, timeUnit = TimeUnit.MILLISECONDS) | |
@Measurement(iterations = 5, time = 1000, timeUnit = TimeUnit.MILLISECONDS) | |
@Threads(1) | |
public class HashPerf { | |
public static void main(String[] args) throws RunnerException { | |
Options opt = new OptionsBuilder() | |
.include(HashPerf.class.getSimpleName()) | |
.warmupIterations(5) | |
.measurementIterations(5) | |
.build(); | |
new Runner(opt).run(); | |
} | |
@State(Scope.Benchmark) | |
public static class BenchmarkState { | |
final HashMap<String, Object> juhm = new HashMap<>(); | |
final THashMap<String, Object> thm = new THashMap<>(); | |
final Object value = new Object(); | |
final String[] strings = new String[]{ | |
"id", | |
"batch", | |
"batchRun", | |
"isin", | |
"cusip", | |
"instrument", | |
"sequenceNumber", | |
"instrumentSet", | |
"asOf", | |
"priceType", | |
"priceSource", | |
"assumedMaturityDate", | |
"primaryIssuerSet", | |
"bidPrice", | |
"midPrice", | |
"askPrice", | |
"bidAskPriceSpread", | |
"bidYieldToMaturity", | |
"midYieldToMaturity", | |
"askYieldToMaturity", | |
"bidAskYieldSpread", | |
"bidDiscountMargin", | |
"midDiscountMargin", | |
"askDiscountMargin", | |
"benchmarkIsin", | |
"benchmarkCusip", | |
"benchmarkName", | |
"bidBenchmarkYieldToMaturity", | |
"midBenchmarkYieldToMaturity", | |
"askBenchmarkYieldToMaturity", | |
"bidDirtyPrice", | |
"midDirtyPrice", | |
"askDirtyPrice", | |
"bidSpreadToBenchmark", | |
"midSpreadToBenchmark", | |
"askSpreadToBenchmark", | |
"accruedInterest", | |
"bidASpread", | |
"midASpread", | |
"askASpread", | |
"bidZSpread", | |
"midZSpread", | |
"askZSpread", | |
"bidYieldToWorst", | |
"askYieldToWorst", | |
"midYieldToWorst", | |
"yieldToWorstDate", | |
"bidYieldToWorstPrice", | |
"bidApplicableYield", | |
"midApplicableYield", | |
"askApplicableYield", | |
"applicableYieldDate", | |
"applicableYieldType", | |
"bidApplicableSpread", | |
"midApplicableSpread", | |
"askApplicableSpread", | |
"applicableSpreadType", | |
"midISpread", | |
"bidGSpread", | |
"midGSpread", | |
"askGSpread", | |
"midPv01", | |
"bidMacaulayDuration", | |
"midMacaulayDuration", | |
"askMacaulayDuration", | |
"bidModifiedDuration", | |
"midModifiedDuration", | |
"askModifiedDuration", | |
"bidConvexity", | |
"midConvexity", | |
"askConvexity", | |
"bidEffectiveDuration", | |
"midEffectiveDuration", | |
"askEffectiveDuration", | |
"bidEffectiveConvexity", | |
"midEffectiveConvexity", | |
"askEffectiveConvexity", | |
"midActualCdsBondBasis", | |
"midActualImmCdsBondBasis", | |
"cdsBondBasisAsOf", | |
"bidOas", | |
"midOas", | |
"askOas", | |
"midOasOptionPrice", | |
"bidOasOptionPrice", | |
"askOasOptionPrice", | |
"bidSpreadToWorst", | |
"askSpreadToWorst", | |
"midSpreadToWorst", | |
"bidModifiedDurationToWorstOrMaturity", | |
"midModifiedDurationToWorstOrMaturity", | |
"askModifiedDurationToWorstOrMaturity", | |
"bidMacauleyDurationToWorstOrMaturity", | |
"midMacauleyDurationToWorstOrMaturity", | |
"askMacauleyDurationToWorstOrMaturity", | |
"bidConvexityToWorstOrMaturity", | |
"midConvexityToWorstOrMaturity", | |
"askConvexityToWorstOrMaturity", | |
"fuel1", | |
"fuel2", | |
"fuel3", | |
"fuel4", | |
"fuel5", | |
"rankedFuelSourceCount", | |
"quotesCount1Day", | |
"quotesCount10Day", | |
"liquidityScore", | |
"liquidityAsOf", | |
"quotesDealerCount1Day", | |
"quotesDealerCount10Day", | |
"shadowLiquidity", | |
"compositeDepthCount", | |
"maturityMerit", | |
"depthMerit", | |
"bidAskMerit", | |
"meritCount", | |
"uniqueFuelCount", | |
"bidAskCalculationType", | |
"hasBondAgencyData", | |
"hasIboxx", | |
"hasIcap", | |
"hasMarkitComposite", | |
"hasMarkitContribution", | |
"hasQuote", | |
"hasTraceData", | |
"hasIdb", | |
"lastObservedDate", | |
"dealerCount1Day", | |
"dealerCount10Day", | |
"liquidityScore7Day", | |
"liquidityScore30Day", | |
"liquidityScore60Day", | |
"liquidityScore90Day", | |
"liquidityScore7DayCount", | |
"liquidityScore30DayCount", | |
"liquidityScore60DayCount", | |
"liquidityScore90DayCount", | |
"quotesCount7Day", | |
"bidSpreadToBenchmark2Y", | |
"midSpreadToBenchmark2Y", | |
"askSpreadToBenchmark2Y", | |
"bidSpreadToBenchmark3Y", | |
"midSpreadToBenchmark3Y", | |
"askSpreadToBenchmark3Y", | |
"bidSpreadToBenchmark5Y", | |
"midSpreadToBenchmark5Y", | |
"askSpreadToBenchmark5Y", | |
"bidSpreadToBenchmark7Y", | |
"midSpreadToBenchmark7Y", | |
"askSpreadToBenchmark7Y", | |
"bidSpreadToBenchmark10Y", | |
"midSpreadToBenchmark10Y", | |
"askSpreadToBenchmark10Y", | |
"bidSpreadToBenchmark30Y", | |
"midSpreadToBenchmark30Y", | |
"askSpreadToBenchmark30Y", | |
"benchmark2YIsin", | |
"benchmark3YIsin", | |
"benchmark5YIsin", | |
"benchmark7YIsin", | |
"benchmark10YIsin", | |
"benchmark30YIsin", | |
"isinFuel1", | |
"isinFuel2", | |
"isinFuel3", | |
"isinFuel4", | |
"isinFuel5", | |
"billingCode" | |
}; | |
} | |
@Benchmark | |
public void javaUtilMapStringKeyInsert(BenchmarkState state, Blackhole bh) throws IOException { | |
for(String str : state.strings) { | |
state.juhm.put(str, state.value); | |
} | |
bh.consume(state.juhm.size()); | |
} | |
@Benchmark | |
public void troveMapStringKeyInsert(BenchmarkState state, Blackhole bh) throws IOException { | |
for(String str : state.strings) { | |
state.thm.put(str, state.value); | |
} | |
bh.consume(state.thm.size()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment