python - Drawing sine curve in Memory-Used view of Task Manager on Windows 10? -
i trying write simple proof-of-concept script on windows 10 let's me draw absolute of sin curve in task manager memory window.
my code follows:
import time import math import gc import sys x = 1 string_drawer = [] while true: #formula eqaution (sin curve) y = (abs(math.sin(math.radians(100*x))))*512000000 print (y, type(y)) #making y type 'int' can used append y = int(round(y)) print (y, type(y)) #checking size of string_drawer debugging print(sys.getsizeof(string_drawer)) #loop used appending if sys.getsizeof(string_drawer) < y: #if y bigger, find difference , append y = y - sys.getsizeof(string_drawer) string_drawer.append(' ' *y) elif sys.getsizeof(string_drawer) > y: #if y smaller, delete variable , make new 1 string_drawer = [] *y else: #if y same size string_drawer, nothing string_drawer = string_drawer #call python gerbage colector gc.collect() #sleep make sure task manager catches change in ram usage time.sleep(0.5) #increment x x += 1 print(x, type(x))
what getting follows:
what want this:
do have idea of doing wrong? guess is within if loop or regarding garbage collector.
any appreciated. :)
sys.getsizeof(string_drawer)
return size of object in bytes. object can type of object. built-in objects return correct results, not have hold true third-party extensions implementation specific.
only memory consumption directly attributed object accounted for, not memory consumption of objects refers to.
and appending list of strings getsizeof return memory attributed list not size of strings of spaces refers to. change list string
string_drawer = '' string_drawer += ' ' * y
but can , should use len
instead of sys.getsizeof
because later adds size of garbage collector (although if string large enough negligible), if want nothing nothing, remove lines:
else: #if y same size string_drawer, nothing string_drawer = string_drawer
and reset string string_drawer = ''
, not list string_drawer = [] * y
update: since python 3.6.2 sys.getsizeof
changed account size of referenced objects too.
bpo-12414: sys.getsizeof() on code object returns sizes includes code struct , sizes of objects references. patch dong-hee na.
Comments
Post a Comment