I associate the key with the hash card 10,000,000 times. Here's the Java code and output:
import java.util.HashMap; public class TestMap { public static void main(String[] args) { HashMap<Integer, Integer> mp = new HashMap<Integer, Integer>(); long start = System.currentTimeMillis(); for (int i = 0; i < 10000000; i++) { mp.put(1, 1); } long end = System.currentTimeMillis(); System.out.println("Elapsed time: " + (end - start) + " msecs"); } } $ javac TestMap.java && java -cp . TestMap Elapsed time: 38 msecs
And then I call java from clojure in REPL:
user=> (import java.util.HashMap) java.util.HashMap user=> (def mp (HashMap.))
Both codes do the same, but the clojure version is slower!
What is the problem?
source share