Created
June 9, 2016 07:34
-
-
Save zakki/66d785b4a9d3c64bc9f8199d7e290e07 to your computer and use it in GitHub Desktop.
Eclipse collections http://vaskir.blogspot.jp/2016/05/hash-maps-rust-vs-f.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Random; | |
import org.eclipse.collections.api.map.primitive.MutableIntIntMap; | |
import org.eclipse.collections.impl.factory.primitive.IntIntMaps; | |
public class Main { | |
public static void time(String name, Runnable f) { | |
long s = System.nanoTime(); | |
f.run(); | |
System.out.println(String.format("%s: %d elapsed.", name, (long)(((System.nanoTime() - s) / 1e6)))); | |
} | |
public static void main(String[] args) { | |
int[] source = new int[50000000]; | |
Random r = new Random(); | |
for (int i =0; i < source.length; i++) | |
source[i] = r.nextInt(); | |
// Map<Integer, Integer> m = new HashMap<>(); | |
// MutableMap<Integer, Integer> m = Maps.mutable.empty(); | |
MutableIntIntMap m = IntIntMaps.mutable.empty(); | |
time("Insertion", () -> { | |
for (int x : source) { | |
m.put(x, 0); | |
} | |
}); | |
time("Lookups", () -> { | |
int acc = 0; | |
for (int x : source) { | |
acc += m.get(x) % 10; | |
} | |
System.out.println(acc); | |
}); | |
} | |
} | |
// Insertion: 3399 elapsed. | |
// Lookups: 1494 elapsed. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment