python 2 simple for loop high memory usage -
this question has answer here:
testing python 2.7 , 3.5
for in range(0, 1000000000): pass
when i'm running code python3 fine (less 3mb memory usage)
but python2 memory usage 32gb (my server has 32gb of ram)
how fix python 2.7?
range
in python 2.7 , range
in python 3 different functions. in python 3 returns iterator provides values 1 one. in python 2.7 returns array memory has allocated. can solved using xrange
function in python version 2.7.
python 2.7.12 >>> range(10) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> xrange(10) xrange(10) >>> iterator = iter(xrange(10)) >>> iterator.next() 0 >>> iterator.next() 1 >>> iterator.next() 2
Comments
Post a Comment