[pypy-commit] extradoc extradoc: update the example
fijal
noreply at buildbot.pypy.org
Tue Mar 6 19:40:22 CET 2012
Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: extradoc
Changeset: r4124:a55dff3ff5ee
Date: 2012-03-06 10:40 -0800
http://bitbucket.org/pypy/extradoc/changeset/a55dff3ff5ee/
Log: update the example
diff --git a/talk/pycon2012/tutorial/examples/03_memory.py b/talk/pycon2012/tutorial/examples/03_memory.py
--- a/talk/pycon2012/tutorial/examples/03_memory.py
+++ b/talk/pycon2012/tutorial/examples/03_memory.py
@@ -1,12 +1,6 @@
import time, os, re
-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
@@ -18,6 +12,12 @@
if 'heap' in line:
mark = True
+class A(object):
+ def __init__(self, a, b, c):
+ self.a = a
+ self.b = b
+ self.c = c
+
def main():
l = []
count = 0
diff --git a/talk/pycon2012/tutorial/examples/07_itertools.py b/talk/pycon2012/tutorial/examples/07_itertools.py
--- a/talk/pycon2012/tutorial/examples/07_itertools.py
+++ b/talk/pycon2012/tutorial/examples/07_itertools.py
@@ -16,8 +16,17 @@
s = 0
for i in range(len(vector1)):
s += vector1[i] + vector2[i]
+ return s
+
+def four(vector1, vector2):
+ return sum(vector1[i] + vector2[i] for i in range(len(vector1)))
+
+def five(vector1, vector2):
+ return sum([vector1[i] + vector2[i] for i in range(len(vector1))])
print "one", timeit.timeit(lambda : one(vector1, vector2), number=1000)
print "two", timeit.timeit(lambda : two(vector1, vector2), number=1000)
print "three", timeit.timeit(lambda : three(vector1, vector2), number=1000)
+print "four", timeit.timeit(lambda : four(vector1, vector2), number=1000)
+print "five", timeit.timeit(lambda : five(vector1, vector2), number=1000)
More information about the pypy-commit
mailing list