Skip to content

Instantly share code, notes, and snippets.

@Fatimamostafa
Last active October 16, 2017 17:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fatimamostafa/22850f4c5460f112a2621f4e09e0a90b to your computer and use it in GitHub Desktop.
Save Fatimamostafa/22850f4c5460f112a2621f4e09e0a90b to your computer and use it in GitHub Desktop.
Store data in memory with collection. Compare memory allocation performance.
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