Skip to content

Instantly share code, notes, and snippets.

@worldmind
Created October 9, 2019 13:20
Show Gist options
  • Save worldmind/59e5eb0a22ebe12a8af412525a1d6248 to your computer and use it in GitHub Desktop.
Save worldmind/59e5eb0a22ebe12a8af412525a1d6248 to your computer and use it in GitHub Desktop.
Comparing of tuple, lis, array memory using
from array import array
from pympler.asizeof import asizeof
SIZE = 1000
the_array = array('i')
the_list = []
for_tuple = []
for i in range(SIZE):
for_tuple.append(i)
the_array.append(i + 1000)
the_list.append(i + 2000)
the_tuple = tuple(for_tuple)
del for_tuple
print(f"Tuple: {asizeof(the_tuple)}")
print(f"Array: {asizeof(the_array)}")
print(f"List: {asizeof(the_list)}")
@worldmind
Copy link
Author

 $ python3 list-size.py                                                                                                                      
Tuple: 40040
Array: 4184
List: 41024

@worldmind
Copy link
Author

worldmind commented Oct 9, 2019

 $ python3 --version                                                                                                                         
Python 3.6.8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment