File tree 1 file changed +16
-6
lines changed
1 file changed +16
-6
lines changed Original file line number Diff line number Diff line change 8
8
9
9
from matplotlib .cbook import report_memory
10
10
import numpy as np
11
- from pylab import figure , show , close
12
-
11
+ import matplotlib .pyplot as plt
13
12
# take a memory snapshot on indStart and compare it with indEnd
14
13
15
14
rand = np .random .rand
16
15
17
16
indStart , indEnd = 200 , 401
17
+ mem_size , coll_count = [], []
18
18
for i in range (indEnd ):
19
19
20
- fig = figure (1 )
20
+ fig = plt . figure (1 )
21
21
fig .clf ()
22
22
23
23
t1 = np .arange (0.0 , 2.0 , 0.01 )
39
39
ax .pcolor (10 * rand (50 , 50 ))
40
40
41
41
fig .savefig ('tmp%d' % i , dpi = 75 )
42
- close (1 )
42
+ plt . close (1 )
43
43
44
- gc .collect ()
44
+ coll = gc .collect ()
45
45
val = report_memory (i )
46
46
print (i , val )
47
47
if i == indStart :
48
48
start = val # wait a few cycles for memory usage to stabilize
49
+ mem_size .append (val )
50
+ coll_count .append (coll )
49
51
50
52
end = 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