RFR: [6904367]: (coll) IdentityHashMap is resized before exceeding the expected maximum size (original) (raw)

Patrick Wright pdoubleya at gmail.com
Mon Jul 14 12:12:07 UTC 2014


Hi

been watching this fascinating discussion - seeing Jeff's benchmark today, was wondering if there isn't already at least one benchmark written with JMH? Wouldn't it make sense to make that part of the submission, as a standard practice in refactoring like this?

Regards, Patrick

On Mon, Jul 14, 2014 at 2:24 AM, Jeff Hain <jeffhain at rocketmail.com> wrote:

>Can you post the benchmark source? Before the source, here are the time ranges runs were stabilizing in for lucky executions (using 1.7 for compiler compliance level, and win7 / core i7) : | original | peter7 | peter7 | peter8 | peter8 | | | | no loop | | no loop | ---------+----------+----------+----------+----------+----------+ jdk7u51 | 0.56-59s | 0.66-68s | 0.62-64s | 0.60-63s | 0.70-74s | jdk8u20 | 0.54-58s | 0.64-66s | 0.58-60s | 0.58-61s | 0.73-76s | jdk9 | 0.59-61s | 0.65-67s | 0.73-75s | 0.60-63s | 0.76-78s | => The no-loop version seems only better for jdk <= 8 and your webrev 07,_ _and for webrev 08, it seems actually (much) worse whatever the jdk._ _=> jdk 8 looks faster than 7, but for some reason also faster than 9. public class IdentityHashMapPerf { private static final int MAXNBROFMAPPINGS = 1*1000; private static final int MAXNBROFCALLS = 10010001000; private static final int NBROFRUNS = 10; public static void main(String[] args) { System.out.println(IdentityHashMapPerf.class.getSimpleName()+"..."); for (int k=0;k<NBROFRUNS;k++) {_ _// Quick run for code discovery for k = 0._ _final int maxNbrOfCalls = (k == 0) ? MAXNBROFMAPPINGS_ _: MAXNBROFCALLS;_ _benchput(new IdentityHashMap<Integer, Integer>(), maxNbrOfCalls); //benchput(new IdentityHashMapPeter7<Integer, Integer>(), maxNbrOfCalls); //benchput(new IdentityHashMapPeter7NoLoop<Integer,_ _Integer>(), maxNbrOfCalls); //benchput(new IdentityHashMapPeter8<Integer, Integer>(), maxNbrOfCalls); //benchput(new IdentityHashMapPeter8NoLoop<Integer,_ _Integer>(), maxNbrOfCalls); } System.out.println("..."+IdentityHashMapPerf.class.getSimpleName()); } private static void benchput(Map<Integer, Integer> map, int maxNbrOfCalls) { for (int k=0;k<2;k++) { final Integer[] keys = newKeys(MAXNBROFMAPPINGS); final int nbrOfClearAndPuts = maxNbrOfCalls/MAXNBROFMAPPINGS; long a = System.nanoTime(); { for (int cap=0;cap<nbrOfClearAndPuts;cap++) { map.clear(); for (int i=0;i<MAXNBROFMAPPINGS;i++) { final Integer kv = keys[i]; map.put(kv, kv); } if (map.size() != MAXNBROFMAPPINGS) { throw new AssertionError("anti optim"); } } } long b = System.nanoTime(); System.out.println(nbrOfClearAndPuts+" * "+MAXNBROFMAPPINGS +" "+map.getClass().getSimpleName()+".put(,) took "+((b-a)/1e9)+" s"); } } private static Integer[] newKeys(int size) { final Integer[] keys = new Integer[size]; for (int i=0;i<keys.length;i++) { keys[i] = i; } return keys; } } -Jeff



More information about the core-libs-dev mailing list