[pypy-commit] extradoc extradoc: Now processing 640x480 images at 38 fps!

hakanardo noreply at buildbot.pypy.org
Sat Jun 11 18:37:18 CEST 2011


Author: Hakan Ardo <hakan at debian.org>
Branch: extradoc
Changeset: r3644:e72bcae07733
Date: 2011-06-11 18:36 +0200
http://bitbucket.org/pypy/extradoc/changeset/e72bcae07733/

Log:	Now processing 640x480 images at 38 fps!

diff --git a/talk/iwtc11/benchmarks/image/io.py b/talk/iwtc11/benchmarks/image/io.py
--- a/talk/iwtc11/benchmarks/image/io.py
+++ b/talk/iwtc11/benchmarks/image/io.py
@@ -21,7 +21,7 @@
         if not self.width:
             self.mplayer = os.popen('mplayer -really-quiet -noframedrop - ' +
                                     '2> /dev/null ', 'w')
-            self.mplayer.write('YUV4MPEG2 W%d H%d F25:1 Ip A1:1\n' %
+            self.mplayer.write('YUV4MPEG2 W%d H%d F100:1 Ip A1:1\n' %
                                (img.width, img.height))
             self.width = img.width
             self.height = img.height
diff --git a/talk/iwtc11/benchmarks/image/sobel.py b/talk/iwtc11/benchmarks/image/sobel.py
--- a/talk/iwtc11/benchmarks/image/sobel.py
+++ b/talk/iwtc11/benchmarks/image/sobel.py
@@ -33,6 +33,18 @@
         res[p] = min(max(int(img[p]), 0), 255)
     return res
 
+def sobel_magnitude_uint8(img):
+    res = img.clone(typecode='B')
+    for p in img.pixeliter():
+        dx = -1.0 * img[p + (-1,-1)] + 1.0 * img[p + (1,-1)] + \
+             -2.0 * img[p + (-1, 0)] + 2.0 * img[p + (1, 0)] + \
+             -1.0 * img[p + (-1, 1)] + 1.0 * img[p + (1, 1)]
+        dy = -1.0*img[p + (-1,-1)] -2.0*img[p + (0,-1)] -1.0*img[p + (1,-1)] + \
+              1.0*img[p + (-1, 1)] +2.0*img[p + (0, 1)] +1.0*img[p + (1, 1)]
+        res[p] = min(int(sqrt(dx*dx + dy*dy) / 4.0), 255)
+    return res
+
+
 if __name__ == '__main__':
     from io import mplayer, view
     import sys
@@ -41,7 +53,7 @@
     if len(sys.argv) > 1:
         fn = sys.argv[1]
     else:
-        fn = 'test.avi'
+        fn = 'test.avi -vf scale=640:480 -benchmark'
 
     sys.setcheckinterval(2**30)
     try:
@@ -50,10 +62,14 @@
     except ImportError:
         pass
 
-    start = time()
+    start = start0 = time()
     for fcnt, img in enumerate(mplayer(NoBorderImagePadded, fn)):
         #view(img)
         #sobeldx(img)
-        view(uint8(sobel_magnitude(img)))
-        print 1.0 / (time() - start), 'fps'
+        #view(uint8(sobel_magnitude(img)))
+        #view(sobel_magnitude_uint8(img))
+        sobel_magnitude_uint8(img)
+        print 1.0 / (time() - start), 'fps, ', (fcnt-2) / (time() - start0), 'average fps'
         start = time()
+        if fcnt==2:
+            start0 = time()
diff --git a/talk/iwtc11/benchmarks/image/time_sobel.py b/talk/iwtc11/benchmarks/image/time_sobel.py
--- a/talk/iwtc11/benchmarks/image/time_sobel.py
+++ b/talk/iwtc11/benchmarks/image/time_sobel.py
@@ -1,5 +1,5 @@
 from noborder import NoBorderImagePadded, NoBorderImage
-from sobel import sobel_magnitude
+from sobel import sobel_magnitude, sobel_magnitude_uint8
 from time import time
 import sys
 
@@ -14,9 +14,16 @@
 n = 1000
 
 sobel_magnitude(Image(n, n))
-
+sobel_magnitude_uint8(Image(n, n, typecode='B'))
+    
 a = time()
 for i in range(10):
     sobel_magnitude(Image(n, n))
 b = time()
 print 'sobel(%s):' % Image.__name__, b - a
+
+a = time()
+for i in range(10):
+    sobel_magnitude_uint8(Image(n, n, typecode='B'))
+b = time()
+print 'sobel_uint8(%s):' % Image.__name__, b - a


More information about the pypy-commit mailing list