[pypy-commit] extradoc extradoc: IN-PROGRESS rewrite benchmarks a bit, can't run convolution due to lack of RAM

fijal noreply at buildbot.pypy.org
Tue Jun 14 21:35:48 CEST 2011


Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: extradoc
Changeset: r3679:8f85b55224b7
Date: 2011-06-14 21:38 +0200
http://bitbucket.org/pypy/extradoc/changeset/8f85b55224b7/

Log:	IN-PROGRESS rewrite benchmarks a bit, can't run convolution due to
	lack of RAM

diff --git a/talk/iwtc11/benchmarks/benchmark.sh b/talk/iwtc11/benchmarks/benchmark.sh
--- a/talk/iwtc11/benchmarks/benchmark.sh
+++ b/talk/iwtc11/benchmarks/benchmark.sh
@@ -1,31 +1,38 @@
-#!/bin/sh
+#!/bin/bash
 
 echo
 echo $*
-if [ $1 == "gcc" ]; then
-    $* sqrt/sqrt_double.c; /usr/bin/time -f %e ./a.out > /dev/null
-    $* sqrt/sqrt_long.c; /usr/bin/time -f %e ./a.out > /dev/null
-    $* sqrt/sqrt_fix16.c; /usr/bin/time -f %e ./a.out > /dev/null
-    $* convolution/conv3.c -lm; /usr/bin/time -f %e ./a.out 1 > /dev/null
-    $* convolution/conv5.c -lm; /usr/bin/time -f %e ./a.out 1 > /dev/null
-    $* convolution/conv3.c -lm; /usr/bin/time -f %e ./a.out 100 > /dev/null
-    $* convolution/conv5.c -lm; /usr/bin/time -f %e ./a.out 100 > /dev/null
-    $* convolution/conv3.c -lm; /usr/bin/time -f %e ./a.out 1000 > /dev/null
-    $* convolution/conv5.c -lm; /usr/bin/time -f %e ./a.out 1000 > /dev/null
-    $* convolution/conv3x3.cc -lstdc++; /usr/bin/time -f %e ./a.out 1000000 3 > /dev/null
-    $* convolution/conv3x3.cc -lstdc++; /usr/bin/time -f %e ./a.out 1000 1000 > /dev/null
-    $* convolution/dilate3x3.cc -lstdc++; /usr/bin/time -f %e ./a.out 1000 1000 > /dev/null
-    $* image/sobel.cc -lstdc++; /usr/bin/time -f %e ./a.out 1002 1002 > /dev/null
+if [ "$1" == "gcc" ]; then
+    ./runner.py -n 5 -c "$*" sqrt/sqrt_double.c
+    ./runner.py -n 5 -c "$*" sqrt/sqrt_long.c
+    ./runner.py -n 5 -c "$*" sqrt/sqrt_fix16.c
+    ./runner.py -n 5 -c "$* -lm" convolution/conv3.c 1
+    ./runner.py -n 5 -c "$* -lm" convolution/conv5.c 1
+    ./runner.py -n 5 -c "$* -lm" convolution/conv3.c 100
+    ./runner.py -n 5 -c "$* -lm" convolution/conv5.c 100
+    ./runner.py -n 5 -c "$* -lm" convolution/conv3.c 1000
+    ./runner.py -n 5 -c "$* -lm" convolution/conv5.c 1000
+    ./runner.py -n 5 -c "$* -lstdc++" convolution/conv3x3.cc 1000000 3
+    ./runner.py -n 5 -c "$* -lstdc++" convolution/conv3x3.cc 1000 1000
+    ./runner.py -n 5 -c "$* -lstdc++" convolution/dilate3x3.cc 1000 1000
+    ./runner.py -n 5 -c "$* -lstdc++" image/sobel.cc 1002 1002
     rm a.out
 else
-    $* sqrt/time_sqrt.py float
-    $* sqrt/time_sqrt.py int
-    $* sqrt/time_sqrt.py Fix16
-    $* convolution/time_conv.py 1
-    $* convolution/time_conv.py 100
-    $* convolution/time_conv.py 1000
-    $* convolution/time_conv2d.py
-    $* image/noborder.py NoBorderImagePadded
-    $* image/noborder.py NoBorderImage
-    $* image/time_sobel.py NoBorderImagePadded
+    #./runner.py -n 10 sqrt/sqrt.py main int
+    #./runner.py -n 10 sqrt/sqrt.py main float
+    #./runner.py -n 10 sqrt/sqrt.py main Fix16
+    ./runner.py convolution/convolution.py conv3 1
+    ./runner.py convolution/convolution.py conv3 100
+    ./runner.py convolution/convolution.py conv3 1000
+
+#    $* sqrt/time_sqrt.py float
+#    $* sqrt/time_sqrt.py int
+#    $* sqrt/time_sqrt.py Fix16
+#    $* convolution/time_conv.py 1
+#    $* convolution/time_conv.py 100
+#    $* convolution/time_conv.py 1000
+#    $* convolution/time_conv2d.py
+#    $* image/noborder.py NoBorderImagePadded
+#    $* image/noborder.py NoBorderImage
+#    $* image/time_sobel.py NoBorderImagePadded
 fi
diff --git a/talk/iwtc11/benchmarks/convolution/convolution.py b/talk/iwtc11/benchmarks/convolution/convolution.py
--- a/talk/iwtc11/benchmarks/convolution/convolution.py
+++ b/talk/iwtc11/benchmarks/convolution/convolution.py
@@ -1,6 +1,6 @@
 from array import array
 
-def conv3(a, k, n=1):
+def _conv3(a, k, n=1):
     assert len(k)==3
     b = array(a.typecode, [0]) * (len(a) - 2)
     while n:
@@ -9,7 +9,13 @@
             b[i] = k[2]*a[i] + k[1]*a[i+1] + k[0]*a[i+2]
     return b
 
-def conv5(a, k, n=1):
+def conv3(args):
+    n = int(args[0])
+    _conv3(array('d', [1]) * (100000000/n),
+          array('d', [-1, 0, 1]), n)
+
+
+def _conv5(a, k, n=1):
     assert len(k)==5
     b = array(a.typecode, [0]) * (len(a) - 4)
     while n:
@@ -44,7 +50,7 @@
                 self[x, y] = data[y][x]
         return self
 
-def conv3x3(a, k):
+def _conv3x3(a, k):
     assert k.width == k.height == 3
     b = Array2D(a.width, a.height)
     for y in xrange(1, a.height-1):
@@ -54,7 +60,7 @@
                       k[2,0]*a[x-1, y+1] + k[1,0]*a[x, y+1] + k[0,0]*a[x+1, y+1]
     return b
 
-def morphology3x3(a, k, func):
+def _morphology3x3(a, k, func):
     assert k.width == k.height == 3
     b = Array2D(a.width, a.height)
     for y in xrange(1, a.height-1):
@@ -64,8 +70,8 @@
                            k[2,0]*a[x-1, y+1], k[1,0]*a[x, y+1], k[0,0]*a[x+1, y+1])
     return b
 
-def dilate3x3(a, k):
+def _dilate3x3(a, k):
     return morphology3x3(a, k, max)
 
-def erode3x3(a, k):
+def _erode3x3(a, k):
     return morphology3x3(a, k, min)
diff --git a/talk/iwtc11/benchmarks/convolution/test_convolution.py b/talk/iwtc11/benchmarks/convolution/test_convolution.py
--- a/talk/iwtc11/benchmarks/convolution/test_convolution.py
+++ b/talk/iwtc11/benchmarks/convolution/test_convolution.py
@@ -1,28 +1,33 @@
-from convolution import conv3, conv5, conv3x3, Array2D
+from convolution import _conv3, _conv5, _conv3x3, Array2D
 from array import array
 
 def test_conv3():
-    b = conv3(array('d', [1, 2, 3, 4, 5, 6, 7, 8, 9]),
-              array('d', [-1, 0, 1]))
+    b = _conv3(array('d', [1, 2, 3, 4, 5, 6, 7, 8, 9]),
+               array('d', [-1, 0, 1]))
     assert b == array('d', [-2]) * 7
     
 def test_conv5():
-    b = conv5(array('d', [1, 2, 3, 4, 5, 6, 7, 8, 9]),
-              array('d', [1, 1, 2, 2, 3]))
+    b = _conv5(array('d', [1, 2, 3, 4, 5, 6, 7, 8, 9]),
+               array('d', [1, 1, 2, 2, 3]))
     assert b == array('d', [22, 31, 40, 49, 58])
     
 def test_conv3x3():
     a = Array2D(5, 5).setup([[11, 12, 13, 14, 15],
-                             [21, 22, 23, 24, 25],
-                             [31, 32, 33, 34, 35],
-                             [41, 42, 43, 44, 45],
-                             [51, 52, 53, 54, 55]])
+                              [21, 22, 23, 24, 25],
+                              [31, 32, 33, 34, 35],
+                              [41, 42, 43, 44, 45],
+                              [51, 52, 53, 54, 55]])
     k = Array2D(3, 3).setup([[1, 2, 3],
-                             [1, 1, 2],
-                             [2, 1, 1]])
-    b = conv3x3(a, k)
+                              [1, 1, 2],
+                              [2, 1, 1]])
+    b = _conv3x3(a, k)
     assert b == Array2D(5, 5).setup([[0,   0,   0,   0, 0],
                                      [0, 326, 340, 354, 0],
                                      [0, 466, 480, 494, 0],
                                      [0, 606, 620, 634, 0],
                                      [0,   0,   0,   0, 0]])
+
+if __name__ == '__main__':
+    test_conv3()
+    test_conv5()
+    test_conv3x3()
diff --git a/talk/iwtc11/benchmarks/runall.sh b/talk/iwtc11/benchmarks/runall.sh
--- a/talk/iwtc11/benchmarks/runall.sh
+++ b/talk/iwtc11/benchmarks/runall.sh
@@ -1,10 +1,10 @@
 #!/bin/sh
 
-./benchmark.sh pypy
+#./benchmark.sh pypy
 ./benchmark.sh pypy --jit enable_opts=intbounds:rewrite:virtualize:heap:unroll
 ./benchmark.sh pypy --jit enable_opts=intbounds:rewrite:virtualize:heap
-./benchmark.sh gcc
+#./benchmark.sh gcc
 ./benchmark.sh gcc -O2
 ./benchmark.sh gcc -O3 -march=native -fno-tree-vectorize
-./benchmark.sh python2.7
+#./benchmark.sh python2.7
 
diff --git a/talk/iwtc11/benchmarks/runner.py b/talk/iwtc11/benchmarks/runner.py
--- a/talk/iwtc11/benchmarks/runner.py
+++ b/talk/iwtc11/benchmarks/runner.py
@@ -1,7 +1,7 @@
 #!/usr/bin/env python
 """ Usage:
 
-runner.py [-w warmup] [-n times] <file> <extra_args>
+runner.py [-w warmup] [-n times] [-c compile_command] <file> <extra_args>
 
 Where extra_args is either what you pass to python file, if file ends with .py
 or a C compiler and it's options
@@ -21,20 +21,23 @@
                       default=10)
     parser.add_option('-w', dest='warmup', help='number of warmup runs',
                       type=int, default=3)
+    parser.add_option('-c', dest='compile_command',
+                      help='for *.c a compile command')
     options, args = parser.parse_args()
     if args[0].endswith('.py'):
         mod = py.path.local(args[0]).pyimport()
         sys.stderr.write("warming up")
-        args = args[1:]
+        func = getattr(mod, args[1])
+        args = args[2:]
         for i in range(options.warmup):
-            mod.main(args)
+            func(args)
             sys.stderr.write('.')
         sys.stderr.write("\n")
         print >>sys.stderr, "benchmarking"
         all = []
         for i in range(options.no):
             t0 = time.time()
-            mod.main(args)
+            func(args)
             all.append(time.time() - t0)
             print >>sys.stderr, "Next:", all[-1]
         name = mod.name
@@ -42,18 +45,25 @@
         # not needed
         options.warmup = 0
         all = []
-        pipe = subprocess.Popen(args[1:] + [args[0]])
+        l = options.compile_command.split(" ") + [args[0]]
+        pipe = subprocess.Popen(l, stderr=subprocess.PIPE,
+                                stdout=subprocess.PIPE)
         pipe.wait()
+        print >>sys.stderr, pipe.stdout.read()
+        print >>sys.stderr, pipe.stderr.read()
         for i in range(options.no):
-            pipe = subprocess.Popen(['/usr/bin/time', '-f', '%e', './a.out'],
+            pipe = subprocess.Popen(['/usr/bin/time', '-f', '%e', './a.out']
+                                    + args[1:],
                                      stderr=subprocess.PIPE,
                                      stdout=subprocess.PIPE)
             pipe.wait()
-            v = float(pipe.stderr.read().strip("\n"))
+            l = pipe.stderr.read().split(" ")
+            v = float(l[-1].strip("\n"))
             all.append(v)
+            name = l[0][:-1] # strip :
             print >>sys.stderr, "Next: %s" % (v,)
-        name = args[0].split(".")[0].split("/")[-1]
-        
+
+    print >>sys.stderr, "benchmarked", name
     if options.no > 1:
         avg = sum(all) / len(all)
         stddev = (sum([(i - avg) * (i - avg) for i in all]) / (len(all) - 1)) ** 0.5
diff --git a/talk/iwtc11/benchmarks/sqrt/sqrt.py b/talk/iwtc11/benchmarks/sqrt/sqrt.py
--- a/talk/iwtc11/benchmarks/sqrt/sqrt.py
+++ b/talk/iwtc11/benchmarks/sqrt/sqrt.py
@@ -50,5 +50,5 @@
 
 def main(argv):
     global name
-    name = 'sqrt_%s' % argv[0]
+    name = 'sqrt(%s)' % argv[0]
     sqrt(eval(argv[0])(123456), 100000000)
diff --git a/talk/iwtc11/benchmarks/sqrt/sqrt_double.c b/talk/iwtc11/benchmarks/sqrt/sqrt_double.c
--- a/talk/iwtc11/benchmarks/sqrt/sqrt_double.c
+++ b/talk/iwtc11/benchmarks/sqrt/sqrt_double.c
@@ -9,5 +9,6 @@
     x = (x + y/x) / 2.0;
   }
   printf("%f\n", x);
+  fprintf(stderr, "sqrt(float):   ");
   return 0;
 }
diff --git a/talk/iwtc11/benchmarks/sqrt/time_sqrt.py b/talk/iwtc11/benchmarks/sqrt/time_sqrt.py
deleted file mode 100644
--- a/talk/iwtc11/benchmarks/sqrt/time_sqrt.py
+++ /dev/null
@@ -1,17 +0,0 @@
-import sys, time
-from sqrt import sqrt, Fix16
-
-try:
-    import pypyjit
-    pypyjit.set_param(trace_limit=20000)
-except ImportError:
-    pass
-
-type1 = eval(sys.argv[1])
-a = time.time()
-sqrt(type1(123456), 100000000)
-b = time.time()
-name = 'sqrt(%s):' % sys.argv[1]
-print '%12s  ' % name, b - a
-
-    


More information about the pypy-commit mailing list