Last active
October 16, 2017 17:26
-
-
Save Fatimamostafa/22850f4c5460f112a2621f4e09e0a90b to your computer and use it in GitHub Desktop.
Store data in memory with collection. Compare memory allocation performance.
This file contains 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
private Map<Integer, Person> map; | |
private SparseArray<Person> sparseArray; | |
//Memory allocation 17.45 | |
public void onMapBtnClick() { | |
map = new Hashmap(); | |
for(int i = 0; i< 10000; i++) { | |
Person p = new Person(i, "Person " + i); | |
map.put(i, p); | |
} | |
//Memory allocation less 15.35 | |
public void onSparseBtnClick() { | |
sparseArray = new SparseArray<>(); | |
for(int i = 0; i< 10000; i++) { | |
sparseArray.append(i, p); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment