Skip to content

Instantly share code, notes, and snippets.

@vighneshbirodkar
Created June 9, 2014 17:04
Show Gist options
  • Save vighneshbirodkar/ac5b107f47356b5f3053 to your computer and use it in GitHub Desktop.
Save vighneshbirodkar/ac5b107f47356b5f3053 to your computer and use it in GitHub Desktop.
dict vs numpy arrays
import sets
import sys
import memory_profiler as mp
import numpy as np
def test_list(n):
a = np.zeros((n,),dtype = int)
b = np.zeros((n,),dtype = int)
del a
del b
def test_dict(n):
d = {}
for i in range(n):
d[i] = i
del d
size = 10
for i in range(6):
list_mem = mp.memory_usage((test_list,(size,),), max_usage = True )
print '************** ',size,' *****************'
print "List Memory =",list_mem[0],"MB"
dict_mem = mp.memory_usage((test_dict,(size,),), max_usage = True )
print "Dict Memory =",dict_mem[0],"MB"
size *= 10
************** 10 *****************
List Memory = 16.87109375 MB
Dict Memory = 16.88671875 MB
************** 100 *****************
List Memory = 16.88671875 MB
Dict Memory = 16.890625 MB
************** 1000 *****************
List Memory = 16.89453125 MB
Dict Memory = 16.94921875 MB
************** 10000 *****************
List Memory = 17.03515625 MB
Dict Memory = 18.18359375 MB
************** 100000 *****************
List Memory = 17.29296875 MB
Dict Memory = 30.48046875 MB
************** 1000000 *****************
List Memory = 20.09765625 MB
Dict Memory = 145.5390625 MB
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment