[pypy-commit] extradoc extradoc: add another example
fijal
noreply at buildbot.pypy.org
Sat Feb 4 21:33:35 CET 2012
Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: extradoc
Changeset: r4077:1b2e064d275a
Date: 2012-02-04 22:33 +0200
http://bitbucket.org/pypy/extradoc/changeset/1b2e064d275a/
Log: add another example
diff --git a/talk/pycon2012/tutorial/examples.rst b/talk/pycon2012/tutorial/examples.rst
new file mode 100644
--- /dev/null
+++ b/talk/pycon2012/tutorial/examples.rst
@@ -0,0 +1,6 @@
+
+* Refcount example, where it won't work
+
+* A simple speedup example and show performance
+
+* Show memory consumption how it grows for tight instances
diff --git a/talk/pycon2012/tutorial/examples/03_memory.py b/talk/pycon2012/tutorial/examples/03_memory.py
new file mode 100644
--- /dev/null
+++ b/talk/pycon2012/tutorial/examples/03_memory.py
@@ -0,0 +1,42 @@
+
+import time, os, re, gc
+
+class A(object):
+ def __init__(self, a, b, c):
+ self.a = a
+ self.b = b
+ self.c = c
+
+def read_smaps():
+ with open("/proc/%d/smaps" % os.getpid()) as f:
+ mark = False
+ for line in f:
+ if mark:
+ assert line.startswith('Size:')
+ m = re.search('(\d+).*', line)
+ return m.group(0), int(m.group(1))
+ if 'heap' in line:
+ mark = True
+
+def main():
+ l = []
+ count = 0
+ for k in range(100):
+ t0 = time.time()
+ for i in range(100000):
+ l.append(A(1, 2, i))
+ for j in range(4):
+ A(1, 1, 2)
+ count += i
+ print time.time() - t0
+ usage, kb = read_smaps()
+ print usage, kb * 1024 / count, "per instance"
+ gc.collect()
+ usage, kb = read_smaps()
+ print "after collect", usage, kb * 1024 / count, "per instance"
+ #import pdb
+ #pdb.set_trace()
+ time.sleep(1)
+
+if __name__ == '__main__':
+ main()
More information about the pypy-commit
mailing list