diff --git a/jetty-jmh/src/main/java/org/eclipse/jetty/server/jmh/ListVsMapBenchmark.java b/jetty-jmh/src/main/java/org/eclipse/jetty/server/jmh/ListVsMapBenchmark.java index 3292585ec50..6311b79562f 100644 --- a/jetty-jmh/src/main/java/org/eclipse/jetty/server/jmh/ListVsMapBenchmark.java +++ b/jetty-jmh/src/main/java/org/eclipse/jetty/server/jmh/ListVsMapBenchmark.java @@ -58,7 +58,7 @@ public class ListVsMapBenchmark @Param({ "11" }) // average length of known headers in HttpHeader public static int length; - @Param({"1", "10", "20" }) + @Param({"1", "10", "20", "30" }) public static int lookups; @Param({"hits", "misses", "iterate" }) @@ -117,12 +117,17 @@ public class ListVsMapBenchmark private void fill(Fill fill) { - for (int i=0; i t = trials.iterator(); while(t.hasNext()) { + // Look for 4 headers at once because that is what the common case of a + // ResourceService does String one = t.hasNext() ? t.next() : null; String two = t.hasNext() ? t.next() : null; String three = t.hasNext() ? t.next() : null; @@ -145,11 +152,11 @@ public class ListVsMapBenchmark String k = p.key; if (one != null && one.equals(k)) result ^= p.value.hashCode(); - else if (two != null && one.equals(k)) + else if (two != null && two.equals(k)) result ^= p.value.hashCode(); - else if (three != null && one.equals(k)) + else if (three != null && three.equals(k)) result ^= p.value.hashCode(); - else if (four != null && one.equals(k)) + else if (four != null && four.equals(k)) result ^= p.value.hashCode(); } } @@ -274,6 +281,31 @@ public class ListVsMapBenchmark map.put(p.key.toLowerCase(),list); order.add(p); }); + return mapLookup(map, order); + } + + + + @Benchmark + @BenchmarkMode({Mode.Throughput}) + public long testHashMapAndArrayList() throws Exception + { + // This keeps the true ordering of fields + Map> map = new HashMap<>(size); + List order = new ArrayList<>(); + + fill(p-> + { + List list = new ArrayList<>(2); + list.add(p); + map.put(p.key.toLowerCase(),list); + order.add(p); + }); + return mapLookup(map, order); + } + + private long mapLookup(Map> map, List order) + { return test(new Lookup() { @Override