Author: Hakan Ardo <[email protected]>
Branch: extradoc
Changeset: r3759:dc0811f67e2f
Date: 2011-06-21 07:37 +0200
http://bitbucket.org/pypy/extradoc/changeset/dc0811f67e2f/
Log: If enough warmup is discarded, a straight forward implementation
with one guard failure per image row outperforms the no failing
guards version of NoBorderImagePadded.
diff --git a/talk/iwtc11/benchmarks/image/plain.py
b/talk/iwtc11/benchmarks/image/plain.py
new file mode 100644
--- /dev/null
+++ b/talk/iwtc11/benchmarks/image/plain.py
@@ -0,0 +1,67 @@
+from array import array
+from math import sqrt
+
+class Image(object):
+ def __init__(self, w, h, typecode='d', fromfile=None):
+ self.width = w
+ self.height = h
+ if fromfile is not None:
+ self.data = array(typecode)
+ self.data.fromfile(fromfile, w*h)
+ else:
+ self.data = array(typecode, [0]) * (w*h)
+ self.typecode = typecode
+
+ def tofile(self, f):
+ self.data.tofile(f)
+
+ def _idx(self, x, y):
+ if 0 <= x < self.width and 0 <= y < self.height:
+ return y*self.width + x
+ raise IndexError
+
+ def __getitem__(self, (x, y)):
+ return self.data[self._idx(x, y)]
+
+ def __setitem__(self, (x, y), val):
+ self.data[self._idx(x, y)] = val
+
+def sobel_magnitude(a):
+ b = Image(a.width, a.height, typecode='B')
+ for y in xrange(1, a.height-1):
+ for x in xrange(1, a.width-1):
+ dx = -1.0 * a[x-1, y-1] + 1.0 * a[x+1, y-1] + \
+ -2.0 * a[x-1, y] + 2.0 * a[x+1, y] + \
+ -1.0 * a[x-1, y+1] + 1.0 * a[x+1, y+1]
+ dy = -1.0 * a[x-1, y-1] -2.0 * a[x, y-1] -1.0 * a[x+1, y-1] + \
+ 1.0 * a[x-1, y+1] +2.0 * a[x, y+1] +1.0 * a[x+1, y+1]
+ b[x, y] = min(int(sqrt(dx*dx + dy*dy) / 4.0), 255)
+
+ return b
+
+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(img)
+ view(sobel_magnitude(img))
+ #sobel_magnitude(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/sobel.py
b/talk/iwtc11/benchmarks/image/sobel.py
--- a/talk/iwtc11/benchmarks/image/sobel.py
+++ b/talk/iwtc11/benchmarks/image/sobel.py
@@ -78,8 +78,8 @@
#view(img)
#sobeldx(img)
#view(uint8(sobel_magnitude(img)))
- view(sobel_magnitude_uint8(img))
- #sobel_magnitude_uint8(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:
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit