In my Java app, where performance (speed or execution time) is highly important, I use
HPPC classes and java.util.BitSet:
import com.carrotsearch.hppc.IntSet;
import com.carrotsearch.hppc.IntOpenHashSet;
import com.carrotsearch.hppc.IntIntMap;
import com.carrotsearch.hppc.IntIntOpenHashMap;
import com.carrotsearch.hppc.IntObjectMap;
import com.carrotsearch.hppc.IntObjectOpenHashMap;
import java.util.BitSet;
IntSet set = new IntOpenHashSet();
IntIntMap iMap = new IntIntOpenHashMap();
IntObjectMap<int[]> aMap = new IntObjectOpenHashMap<int[]>();
IntObjectMap<BitSet> bMap = new IntObjectOpenHashMap<BitSet>();
and I do such operations:
// n = 62500000000; (multiplier showing relations between operations below)
// constants 12345, 67890, new int[100000] used for presentation purpose only
// this line is executed 15 625 000 000 (= n / 4) times
set.add(12345);
// this line is executed 62 500 000 000 (= n) times
iMap.put(12345, 67890);
// these two lines are executed 62 500 000 000 (= n) times
aMap.put(12345, new int[100000]);
bMap.put(12345, new int[100000]);
// these two lines are executed 125 000 000 000 (= n * 2) times
int[] ints = aMap.get(12345);
BitSet bits = bMap.get(12345);
// these two lines are executed 187 500 000 000 (= n * 3) times
int card = ints.length;
int card = bits.cardinality();
// these two lines are executed 124 999 500 000 (= n * 2 - 500000) times
clonedBits = (BitSet) bits.clone();
clonedBits.and(otherBits);
// this loop (each time iterating bits.cardinality() times) is executed
// 31 250 000 000 (= n / 2) times and the total number of iterations
// equals bits1.cardinality() + ... + bits31250000000.cardinality()
for (int i = bits.nextSetBit(0); i >= 0; i = bits.nextSetBit(i+1)) {
doSomeCode();
}
To conlude, these operations have been used: cardinality(), clone(), and(), nextBitSet() of BitSet class,
get(), put() of each Map class and add() of IntSet class. No other operations have been executed.
Question: what is library to choose in terms of performance (speed) in order to handle above operations efficiently? The list of candidates has been found:
Will benchmark myself, but if somebody knows definitely what is faster and when, please let us know.
Best wishes,
Sophie
> java-high-performance-primitive-collections+unsub...@googlegroups.com.