From 44d4474f955ad03838e40c5f4dd39661442d58bc Mon Sep 17 00:00:00 2001 From: kimchy Date: Thu, 31 Mar 2011 17:48:57 +0200 Subject: [PATCH] anoter small bench --- .../trove/StringMapAdjustOrPutBenchmark.java | 40 ++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/modules/benchmark/micro/src/main/java/org/elasticsearch/benchmark/trove/StringMapAdjustOrPutBenchmark.java b/modules/benchmark/micro/src/main/java/org/elasticsearch/benchmark/trove/StringMapAdjustOrPutBenchmark.java index 4eef265c916..b4281e036c0 100644 --- a/modules/benchmark/micro/src/main/java/org/elasticsearch/benchmark/trove/StringMapAdjustOrPutBenchmark.java +++ b/modules/benchmark/micro/src/main/java/org/elasticsearch/benchmark/trove/StringMapAdjustOrPutBenchmark.java @@ -25,6 +25,7 @@ import org.elasticsearch.common.trove.StringIdentityHashingStrategy; import org.elasticsearch.common.trove.map.custom_hash.TObjectIntCustomHashMap; import org.elasticsearch.common.trove.map.hash.THashMap; import org.elasticsearch.common.trove.map.hash.TIntIntHashMap; +import org.elasticsearch.common.trove.map.hash.TIntObjectHashMap; import org.elasticsearch.common.trove.map.hash.TObjectIntHashMap; import org.elasticsearch.common.trove.strategy.IdentityHashingStrategy; import org.elasticsearch.common.unit.SizeValue; @@ -36,7 +37,7 @@ public class StringMapAdjustOrPutBenchmark { public static void main(String[] args) { - int NUMBER_OF_KEYS = (int) SizeValue.parseSizeValue("200k").singles(); + int NUMBER_OF_KEYS = (int) SizeValue.parseSizeValue("20").singles(); int STRING_SIZE = 5; long PUT_OPERATIONS = SizeValue.parseSizeValue("5m").singles(); long ITERATIONS = 10; @@ -204,6 +205,33 @@ public class StringMapAdjustOrPutBenchmark { intMap.clear(); intMap = null; + + // now test with THashMap + stopWatch = new StopWatch().start(); + TIntObjectHashMap tIntMap = new TIntObjectHashMap(); + for (long iter = 0; iter < ITERATIONS; iter++) { + if (REUSE) { + tIntMap.clear(); + } else { + tIntMap = new TIntObjectHashMap(); + } + for (long i = 0; i < PUT_OPERATIONS; i++) { + int key = iValues[(int) (i % NUMBER_OF_KEYS)]; + IntEntry intEntry = tIntMap.get(key); + if (intEntry == null) { + intEntry = new IntEntry(key, 1); + tIntMap.put(key, intEntry); + } else { + intEntry.counter++; + } + } + } + + tIntMap.clear(); + tIntMap = null; + + stopWatch.stop(); + System.out.println("TIntObjectHashMap: " + stopWatch.totalTime() + ", " + stopWatch.totalTime().millisFrac() / ITERATIONS + "ms"); } @@ -216,4 +244,14 @@ public class StringMapAdjustOrPutBenchmark { this.counter = counter; } } + + static class IntEntry { + int key; + int counter; + + IntEntry(int key, int counter) { + this.key = key; + this.counter = counter; + } + } } \ No newline at end of file