public void testCompactingHashMapPerformance() {
try {
final int NUM_MEM_PAGES = SIZE * NUM_PAIRS / PAGE_SIZE;
MutableObjectIterator<IntPair> buildInput = new UniformIntPairGenerator(NUM_PAIRS, 1, false);
MutableObjectIterator<IntPair> probeTester = new UniformIntPairGenerator(NUM_PAIRS, 1, false);
MutableObjectIterator<IntPair> updater = new UniformIntPairGenerator(NUM_PAIRS, 1, false);
MutableObjectIterator<IntPair> updateTester = new UniformIntPairGenerator(NUM_PAIRS, 1, false);
long start = 0L;
long end = 0L;
long first = System.currentTimeMillis();
System.out.println("Creating and filling CompactingHashMap...");
start = System.currentTimeMillis();
AbstractMutableHashTable<IntPair> table = new CompactingHashTable<IntPair>(serializer, comparator, getMemory(NUM_MEM_PAGES, PAGE_SIZE));
table.open();
IntPair target = new IntPair();
while(buildInput.next(target) != null) {
table.insert(target);
}
end = System.currentTimeMillis();
System.out.println("HashMap ready. Time: " + (end-start) + " ms");
System.out.println("Starting first probing run...");
start = System.currentTimeMillis();
AbstractHashTableProber<IntPair, IntPair> prober = table.getProber(comparator, pairComparator);
IntPair temp = new IntPair();
while(probeTester.next(target) != null) {
assertNotNull(prober.getMatchFor(target, temp));
assertEquals(temp.getValue(), target.getValue());
}
end = System.currentTimeMillis();
System.out.println("Probing done. Time: " + (end-start) + " ms");
System.out.println("Starting update...");
start = System.currentTimeMillis();
while(updater.next(target) != null) {
target.setValue(target.getValue()*-1);
table.insertOrReplaceRecord(target, temp);
}
end = System.currentTimeMillis();
System.out.println("Update done. Time: " + (end-start) + " ms");
System.out.println("Starting second probing run...");
start = System.currentTimeMillis();
while (updateTester.next(target) != null) {
assertNotNull(prober.getMatchFor(target, temp));
assertEquals(target.getValue(), temp.getValue());
}
end = System.currentTimeMillis();
System.out.println("Probing done. Time: " + (end-start) + " ms");