0

The following code shows that Koloboke HashHashObjs maps are very slow at putIfAbsent, is there a design flaw here?

import com.koloboke.collect.map.hash.HashObjObjMaps;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;

public class Koloboke {
  public static void main(String [] args) {
    Map<Long, String> normalMap = new HashMap<>();
    Map<Long, String> kolobokeMap = HashObjObjMaps.newMutableMap();
    long iterations = 100_000;
    for(long i = 0;i<iterations;i++) {
        normalMap.put(i, Long.toString(i));
        kolobokeMap.put(i, Long.toString(i));
    }
    long nanoStart= System.nanoTime();
    for(long i = 0;i<iterations;i++) {
        normalMap.putIfAbsent(i, Long.toString(i));
    }
    System.out.println("hashmap putIfAbsent took " + TimeUnit.NANOSECONDS.toMillis(System.nanoTime()-nanoStart) + " millis");

    nanoStart= System.nanoTime();
    for(long i = 0;i<iterations;i++) {
        kolobokeMap.putIfAbsent(i, Long.toString(i));
    }
    System.out.println("koloboke putIfAbsent took " + TimeUnit.NANOSECONDS.toMillis(System.nanoTime()-nanoStart) + " millis");
  }
}

Output:

hashmap putIfAbsent took 27 millis

koloboke putIfAbsent took 19733 millis

torahmike
  • 420
  • 5
  • 10
  • 1
    I would start by using a proper benchamrking tool like JMH. I would be extremely suspicious of benchmarks done like this, and there's a serious chance they would just produce outright lies. (In context, that's actually highly likely.) – Louis Wasserman Dec 11 '22 at 22:03

0 Answers0