File tree Expand file tree Collapse file tree 1 file changed +42
-0
lines changed
Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change 1+ import os , sys , time
2+ import matplotlib
3+ matplotlib .use ('Agg' )
4+ from matplotlib .matlab import *
5+
6+
7+ def report_memory (i ):
8+ pid = os .getpid ()
9+ a2 = os .popen ('ps -p %d -o rss,sz' % pid ).readlines ()
10+ print i , ' ' , a2 [1 ],
11+ return int (a2 [1 ].split ()[1 ])
12+
13+
14+
15+ # take a memory snapshot on indStart and compare it with indEnd
16+ indStart , indEnd = 10 , 200
17+ for i in range (indEnd ):
18+ ind = arange (100 )
19+ xx = rand (len (ind ))
20+ figure (1 )
21+ subplot (221 )
22+ plot (ind , xx )
23+ subplot (222 )
24+ X = rand (50 ,50 )
25+ imshow (X )
26+
27+ subplot (223 )
28+ scatter (rand (50 ), rand (50 ))
29+ subplot (224 )
30+ pcolor (10 * rand (50 ,50 ))
31+ savefig ('tmp%d' % i , dpi = 75 )
32+ close (1 )
33+
34+ val = report_memory (i )
35+ if i == indStart : start = val # wait a few cycles for memory usage to stabilize
36+
37+ end = val
38+ print 'Average memory consumed per loop: %1.4fk bytes\n ' % ((end - start )/ float (indEnd - indStart ))
39+
40+ """
41+ Average memory consumed per loop: 0.0053k bytes
42+ """
You can’t perform that action at this time.
0 commit comments