[pypy-commit] extradoc extradoc: some more examples
fijal
noreply at buildbot.pypy.org
Sun Mar 4 21:52:02 CET 2012
Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: extradoc
Changeset: r4118:ca428ddeb6f8
Date: 2012-03-04 12:51 -0800
http://bitbucket.org/pypy/extradoc/changeset/ca428ddeb6f8/
Log: some more examples
diff --git a/talk/pycon2012/tutorial/examples/00_examples.py b/talk/pycon2012/tutorial/examples/00_examples.py
new file mode 100644
--- /dev/null
+++ b/talk/pycon2012/tutorial/examples/00_examples.py
@@ -0,0 +1,6 @@
+
+def f(a, b):
+ return a + b
+
+import dis
+dis.dis(f)
diff --git a/talk/pycon2012/tutorial/examples/05_obj_vs_dict.py b/talk/pycon2012/tutorial/examples/05_obj_vs_dict.py
new file mode 100644
--- /dev/null
+++ b/talk/pycon2012/tutorial/examples/05_obj_vs_dict.py
@@ -0,0 +1,44 @@
+
+class A(object):
+ def __init__(self, a, b, c):
+ self.a = a
+ self.b = b
+ self.c = c
+
+def obj_good():
+ a = A(1, 2, 3)
+ s = 0
+ for i in range(SIZE):
+ s += a.a + a.b + a.c
+ return s
+
+def obj_bad():
+ a = A(1, 2, 3)
+ s = 0
+ for i in range(SIZE):
+ a.__dict__[i] = i
+ s += a.__dict__[i]
+ return s
+
+def dict_bad():
+ a = {'a': 1, 'b': 2, 'c': 3}
+ s = 0
+ for i in range(SIZE):
+ s += a['a'] + a['b'] + a['c']
+ return s
+
+def dict_good():
+ a = {}
+ s = 0
+ for i in range(SIZE):
+ a[i] = i
+ s += a[i]
+ return s
+
+import timeit
+SIZE = 10000
+
+print "obj, few", timeit.timeit(obj_good, number=SIZE)
+print "obj, many", timeit.timeit(obj_bad, number=SIZE)
+print "dict, many", timeit.timeit(dict_good, number=SIZE)
+print "dict, few", timeit.timeit(dict_bad, number=SIZE)
diff --git a/talk/pycon2012/tutorial/examples/06_specialized.py b/talk/pycon2012/tutorial/examples/06_specialized.py
new file mode 100644
--- /dev/null
+++ b/talk/pycon2012/tutorial/examples/06_specialized.py
@@ -0,0 +1,7 @@
+
+def f():
+ for i in range(10000):
+ l = [k for k in range(10000)]
+ #l.append(None)
+
+f()
diff --git a/talk/pycon2012/tutorial/slides.rst b/talk/pycon2012/tutorial/slides.rst
--- a/talk/pycon2012/tutorial/slides.rst
+++ b/talk/pycon2012/tutorial/slides.rst
@@ -192,7 +192,7 @@
Specialized lists
=================
-* XXX Example of how much speedup you get out of not mixing
+* xxx
Itertools abuse
===============
More information about the pypy-commit
mailing list