[pypy-commit] extradoc extradoc: magnify example from sprint, now with no generator and more decent performace

hakanardo noreply at buildbot.pypy.org
Tue Jun 21 07:54:13 CEST 2011


Author: Hakan Ardo <hakan at debian.org>
Branch: extradoc
Changeset: r3761:68c1c8d367c2
Date: 2011-06-21 07:58 +0200
http://bitbucket.org/pypy/extradoc/changeset/68c1c8d367c2/

Log:	magnify example from sprint, now with no generator and more decent
	performace

diff --git a/talk/iwtc11/benchmarks/image/magnify.py b/talk/iwtc11/benchmarks/image/magnify.py
new file mode 100644
--- /dev/null
+++ b/talk/iwtc11/benchmarks/image/magnify.py
@@ -0,0 +1,44 @@
+from plain import Image
+from math import atan2, sqrt, sin, cos
+
+def magnify(img):
+    out = Image(img.width, img.height, typecode='B')
+    out.data[:] = img.data
+    maxr = img.height/3
+    for y in xrange(img.height/2 - maxr, img.height/2 + maxr):
+        for x in xrange(img.width/2 - maxr, img.width/2 + maxr):
+            dx, dy = x - img.width/2, y - img.height/2
+            a = atan2(dy, dx)
+            r = sqrt(dx ** 2 + dy ** 2)
+            if r < maxr:
+                nr = r*r / maxr
+                nx, ny = nr*cos(a), nr*sin(a)
+                out[x,y] = img[int(nx) + img.width/2, int(ny) + img.height/2]
+            else:
+                out[x,y] = img[x,y]
+    return out
+
+if __name__ == '__main__':
+    from io import mplayer, view
+    import sys
+    from time import time
+
+    if len(sys.argv) > 1:
+        fn = sys.argv[1]
+    else:
+        fn = 'test.avi -vf scale=640:480 -benchmark'
+
+    sys.setcheckinterval(2**30)
+    try:
+        import pypyjit
+        pypyjit.set_param(trace_limit=200000)
+    except ImportError:
+        pass
+
+    start = start0 = time()
+    for fcnt, img in enumerate(mplayer(Image, fn)):
+        view(magnify(img))
+        print 1.0 / (time() - start), 'fps, ', (fcnt-2) / (time() - start0), 'average fps'
+        start = time()
+        if fcnt==2:
+            start0 = time()


More information about the pypy-commit mailing list