File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 88
99from matplotlib .cbook import report_memory
1010import numpy as np
11- from pylab import figure , show , close
12-
11+ import matplotlib .pyplot as plt
1312# take a memory snapshot on indStart and compare it with indEnd
1413
1514rand = np .random .rand
1615
1716indStart , indEnd = 200 , 401
17+ mem_size , coll_count = [], []
1818for i in range (indEnd ):
1919
20- fig = figure (1 )
20+ fig = plt . figure (1 )
2121 fig .clf ()
2222
2323 t1 = np .arange (0.0 , 2.0 , 0.01 )
3939 ax .pcolor (10 * rand (50 , 50 ))
4040
4141 fig .savefig ('tmp%d' % i , dpi = 75 )
42- close (1 )
42+ plt . close (1 )
4343
44- gc .collect ()
44+ coll = gc .collect ()
4545 val = report_memory (i )
4646 print (i , val )
4747 if i == indStart :
4848 start = val # wait a few cycles for memory usage to stabilize
49+ mem_size .append (val )
50+ coll_count .append (coll )
4951
5052end = val
51- print ('Average memory consumed per loop: %1.4fk bytes\n ' % ((end - start ) / float (indEnd - indStart )))
53+ print ('Average memory consumed per loop: %1.4fk bytes\n ' %
54+ ((end - start ) / float (indEnd - indStart )))
55+ fig , ax = plt .subplots ()
56+ ax2 = ax .twinx ()
57+ ax .plot (mem_size , 'r' )
58+ ax .set_ylabel ('memory size' , color = 'r' )
59+ ax2 .plot (coll_count , 'k' )
60+ ax2 .set_ylabel ('collect count' , color = 'k' )
61+ fig .savefig ('report' )
You can’t perform that action at this time.
0 commit comments