Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- program
- MySQL
- Malaysia
- erlang
- history
- hadoop
- Spain
- Python
- Java
- web
- Italy
- comic agile
- Programming
- Linux
- France
- essay
- Book review
- QT
- programming_book
- management
- Software Engineering
- agile
- ubuntu
- RFID
- leadership
- hbase
- psychology
- django
- Book
- Kuala Lumpur
Archives
- Today
- Total
Collection speed 비교 본문
http://fastutil.dsi.unimi.it/
javac -cp .:./fastutil-6.2.2/fastutil-6.2.2.jar TestSpeed.java
java -cp .:./fastutil-6.2.2/fastutil-6.2.2.jar TestSpeed
Test list speed - puts 1000000 elements for each list 10 times
java.util.ArrayList size() = 10000000 elapsed time = 237 ms
it.unimi.dsi.fastutil.ints.IntArrayList size() = 10000000 elapsed time = 27 ms
Test set speed - puts 1000000 elements for each set 10 times
java.util.HashSet size() = 1000000 elapsed time = 118 ms
java.util.LinkedHashSet size() = 1000000 elapsed time = 101 ms
java.util.TreeSet size() = 1000000 elapsed time = 401 ms
it.unimi.dsi.fastutil.ints.IntOpenHashSet size() = 1000000 elapsed time = 27 ms
it.unimi.dsi.fastutil.ints.IntRBTreeSet size() = 1000000 elapsed time = 395 ms
it.unimi.dsi.fastutil.ints.IntAVLTreeSet size() = 1000000 elapsed time = 393 ms
it.unimi.dsi.fastutil.ints.IntLinkedOpenHashSet size() = 1000000 elapsed time = 50 ms
it.unimi.dsi.fastutil.ints.IntArraySet size() = 1000000 elapsed time = 653766 ms
Test map speed - puts 1000000 elements for each map 10 times
java.util.HashMap key size() = 1000000 elapsed time = 182ms
java.util.LinkedHashMap key size() = 1000000 elapsed time = 277ms
java.util.TreeMap key size() = 1000000 elapsed time = 317ms
it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap key size() = 1000000 elapsed time = 32ms
it.unimi.dsi.fastutil.ints.Int2IntLinkedOpenHashMap key size() = 1000000 elapsed time = 34ms
it.unimi.dsi.fastutil.ints.Int2IntAVLTreeMap key size() = 1000000 elapsed time = 335ms
it.unimi.dsi.fastutil.ints.Int2IntRBTreeMap key size() = 1000000 elapsed time = 357ms
it.unimi.dsi.fastutil.ints.Int2IntArrayMap key size() = 1000000 elapsed time = 684660ms
javac -cp .:./fastutil-6.2.2/fastutil-6.2.2.jar TestSpeed.java
java -cp .:./fastutil-6.2.2/fastutil-6.2.2.jar TestSpeed
Test list speed - puts 1000000 elements for each list 10 times
java.util.ArrayList size() = 10000000 elapsed time = 237 ms
it.unimi.dsi.fastutil.ints.IntArrayList size() = 10000000 elapsed time = 27 ms
Test set speed - puts 1000000 elements for each set 10 times
java.util.HashSet size() = 1000000 elapsed time = 118 ms
java.util.LinkedHashSet size() = 1000000 elapsed time = 101 ms
java.util.TreeSet size() = 1000000 elapsed time = 401 ms
it.unimi.dsi.fastutil.ints.IntOpenHashSet size() = 1000000 elapsed time = 27 ms
it.unimi.dsi.fastutil.ints.IntRBTreeSet size() = 1000000 elapsed time = 395 ms
it.unimi.dsi.fastutil.ints.IntAVLTreeSet size() = 1000000 elapsed time = 393 ms
it.unimi.dsi.fastutil.ints.IntLinkedOpenHashSet size() = 1000000 elapsed time = 50 ms
it.unimi.dsi.fastutil.ints.IntArraySet size() = 1000000 elapsed time = 653766 ms
Test map speed - puts 1000000 elements for each map 10 times
java.util.HashMap key size() = 1000000 elapsed time = 182ms
java.util.LinkedHashMap key size() = 1000000 elapsed time = 277ms
java.util.TreeMap key size() = 1000000 elapsed time = 317ms
it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap key size() = 1000000 elapsed time = 32ms
it.unimi.dsi.fastutil.ints.Int2IntLinkedOpenHashMap key size() = 1000000 elapsed time = 34ms
it.unimi.dsi.fastutil.ints.Int2IntAVLTreeMap key size() = 1000000 elapsed time = 335ms
it.unimi.dsi.fastutil.ints.Int2IntRBTreeMap key size() = 1000000 elapsed time = 357ms
it.unimi.dsi.fastutil.ints.Int2IntArrayMap key size() = 1000000 elapsed time = 684660ms
import java.util.AbstractMap; import java.util.AbstractSet; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.List; import java.util.TreeMap; import java.util.TreeSet; import it.unimi.dsi.fastutil.ints.AbstractInt2IntMap; import it.unimi.dsi.fastutil.ints.AbstractIntList; import it.unimi.dsi.fastutil.ints.AbstractIntSet; import it.unimi.dsi.fastutil.ints.Int2IntAVLTreeMap; import it.unimi.dsi.fastutil.ints.Int2IntArrayMap; import it.unimi.dsi.fastutil.ints.Int2IntLinkedOpenHashMap; import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; import it.unimi.dsi.fastutil.ints.Int2IntRBTreeMap; import it.unimi.dsi.fastutil.ints.IntAVLTreeSet; import it.unimi.dsi.fastutil.ints.IntArrayList; import it.unimi.dsi.fastutil.ints.IntArraySet; import it.unimi.dsi.fastutil.ints.IntLinkedOpenHashSet; import it.unimi.dsi.fastutil.ints.IntOpenHashSet; import it.unimi.dsi.fastutil.ints.IntRBTreeSet; public class TestSpeed { public static void main(String[] args) { int testNum = 10; int elementNum = 1000 * 1000; TestSpeed.testListSpeed(testNum, elementNum); TestSpeed.testSetSpeed(testNum, elementNum); TestSpeed.testMapSpeed(testNum, elementNum); } public static long getElapsedTime(long time0, long time1) { return (time1 - time0) / 1000000; } public static void testListSpeed(final int testNum, final int elementNum) { System.out.println("\nTest list speed - puts " + elementNum + " elements for each list " + testNum + " times\n"); long sum = 0; Listl0 = new ArrayList (); for ( int i = 0; i < testNum; ++i ) { long time0 = System.nanoTime(); for ( int j = 0; j < elementNum; ++j ) l0.add(j); long time1 = System.nanoTime(); sum += getElapsedTime(time0, time1); } System.out.println(l0.getClass().getName() + "\tsize() = " + l0.size() + "\telapsed time = " + (sum / testNum) + " ms"); AbstractIntList l = new IntArrayList(); sum = 0; for ( int i = 0; i < testNum; ++i ) { long time0 = System.nanoTime(); for ( int j = 0; j < elementNum; ++j ) l.add(j); long time1 = System.nanoTime(); sum += getElapsedTime(time0, time1); } System.out.println(l.getClass().getName() + "\tsize() = " + l.size() + "\telapsed time = " + (sum / testNum) + " ms"); } public static void testSetSpeed(final int testNum, final int elementNum) { System.out.println("\nTest set speed - puts " + elementNum + " elements for each set " + testNum + " times\n"); long sum = 0; AbstractSet[] set0 = { new HashSet (), new LinkedHashSet (), new TreeSet () }; for ( int s = 0; s < set0.length; ++s ) { sum = 0; for ( int i = 0; i < testNum; ++i ) { long time0 = System.nanoTime(); for ( int j = 0; j < elementNum; ++j ) set0[s].add(j); long time1 = System.nanoTime(); sum += getElapsedTime(time0, time1); } System.out.println(set0[s].getClass().getName() + "\tsize() = " + set0[s].size() + "\telapsed time = " + (sum / testNum) + " ms"); } AbstractIntSet[] set = { new IntOpenHashSet(), new IntLinkedOpenHashSet(), new IntRBTreeSet(), new IntAVLTreeSet(), new IntArraySet() }; for ( int s = 0; s < set.length; ++s ) { sum = 0; for ( int i = 0; i < testNum; ++i ) { long time0 = System.nanoTime(); for ( int j = 0; j < elementNum; ++j ) set[s].add(j); long time1 = System.nanoTime(); sum += getElapsedTime(time0, time1); } System.out.println(set[s].getClass().getName() + "\tsize() = " + set[s].size() + "\telapsed time = " + (sum / testNum) + " ms"); } } public static void testMapSpeed(final int testNum, final int elementNum) { System.out.println("\nTest map speed - puts " + elementNum + " elements for each map " + testNum + " times\n"); long sum = 0; AbstractMap[] map0 = { new HashMap (), new LinkedHashMap (), new TreeMap () }; for ( int m = 0; m < map0.length; ++m ) { sum = 0; for ( int i = 0; i < testNum; ++i ) { long time0 = System.nanoTime(); for ( int j = 0; j < elementNum; ++j ) map0[m].put(j, j); long time1 = System.nanoTime(); sum += getElapsedTime(time0, time1); } System.out.println(map0[m].getClass().getName() + "\tkey size() = " + map0[m].keySet().size() + "\telapsed time = " + (sum / testNum) + "ms"); } AbstractInt2IntMap[] map = { new Int2IntOpenHashMap(), new Int2IntLinkedOpenHashMap(), new Int2IntAVLTreeMap(), new Int2IntRBTreeMap(), new Int2IntArrayMap() }; for ( int m = 0; m < map.length; ++m ) { sum = 0; for ( int i = 0; i < testNum; ++i ) { long time0 = System.nanoTime(); for ( int j = 0; j < elementNum; ++j ) map[m].put(j, j); long time1 = System.nanoTime(); sum += getElapsedTime(time0, time1); } System.out.println(map[m].getClass().getName() + "\tkey size() = " + map[m].keySet().size() + "\telapsed time = " + (sum / testNum) + "ms"); } } }
Comments