[pypy-svn] r70762 - in pypy/benchmarks: . own

fijal at codespeak.net fijal at codespeak.net
Thu Jan 21 22:26:42 CET 2010


Author: fijal
Date: Thu Jan 21 22:26:40 2010
New Revision: 70762

Added:
   pypy/benchmarks/own/gcbench.py
      - copied, changed from r70761, pypy/trunk/pypy/translator/goal/gcbench.py
Modified:
   pypy/benchmarks/benchmarks.py
Log:
Add gcbench. Mostly for the joy of merging direct-assembler-call branch ;-)


Modified: pypy/benchmarks/benchmarks.py
==============================================================================
--- pypy/benchmarks/benchmarks.py	(original)
+++ pypy/benchmarks/benchmarks.py	Thu Jan 21 22:26:40 2010
@@ -5,10 +5,10 @@
 def relative(*args):
     return os.path.join(os.path.dirname(os.path.abspath(__file__)), *args)
 
-def _register_new_bm(name, d):
+def _register_new_bm(name, d, **opts):
     def Measure(python, options):
         bm_path = relative('own', name + '.py')
-        return MeasureGeneric(python, options, bm_path)
+        return MeasureGeneric(python, options, bm_path, **opts)
     Measure.func_name = 'Measure' + name.capitalize()
 
     def BM(*args, **kwds):
@@ -17,6 +17,10 @@
 
     d[BM.func_name] = BM
 
+opts = {
+    'gcbench' : {'iteration_scaling' : .10},
+}
+
 for name in ['float', 'nbody_modified', 'meteor-contest', 'fannkuch',
-             'spectral-norm', 'chaos', 'telco']:
-    _register_new_bm(name, globals())
+             'spectral-norm', 'chaos', 'telco', 'gcbench']:
+    _register_new_bm(name, globals(), **opts.get(name, {}))

Copied: pypy/benchmarks/own/gcbench.py (from r70761, pypy/trunk/pypy/translator/goal/gcbench.py)
==============================================================================
--- pypy/trunk/pypy/translator/goal/gcbench.py	(original)
+++ pypy/benchmarks/own/gcbench.py	Thu Jan 21 22:26:40 2010
@@ -43,7 +43,7 @@
 #               - No attempt to measure variation with object size
 #               - Results are sensitive to locking cost, but we dont
 #                 check for proper locking
-import os, time
+import os, time, sys
 
 USAGE = """gcbench [num_repetitions] [--depths=N,N,N..] [--threads=N]"""
 ENABLE_THREADS = True
@@ -91,74 +91,87 @@
     "ought to print free/total memory"
     pass
 
-def time_construction(depth):
+def time_construction(depth, debug=False):
     niters = num_iters(depth)
-    print "Creating %d trees of depth %d" % (niters, depth)
+    if debug:
+        print "Creating %d trees of depth %d" % (niters, depth)
     t_start = time.time()
     for i in range(niters):
         temp_tree = Node()
         populate(depth, temp_tree)
         temp_tree = None
     t_finish = time.time()
-    print "\tTop down constrution took %f ms" % ((t_finish-t_start)*1000.)
+    if debug:
+        print "\tTop down constrution took %f ms" % ((t_finish-t_start)*1000.)
     t_start = time.time()
     for i in range(niters):
         temp_tree = make_tree(depth)
         temp_tree = None
     t_finish = time.time()
-    print "\tBottom up constrution took %f ms" % ((t_finish-t_start)*1000.)
+    if debug:
+        print "\tBottom up constrution took %f ms" % ((t_finish-t_start)*1000.)
 
 DEFAULT_DEPTHS = range(kMinTreeDepth, kMaxTreeDepth+1, 2)
 
-def time_constructions(depths):
+def time_constructions(depths, debug=False):
     for d in depths:
-        time_construction(d)
+        time_construction(d, debug)
 
-def time_parallel_constructions(depths, nthreads):
+def time_parallel_constructions(depths, nthreads, debug=False):
     import threading
     threadlist = []
-    print "Starting %d parallel threads..." % (nthreads,)
+    if debug:
+        print "Starting %d parallel threads..." % (nthreads,)
     for n in range(nthreads):
-        t = threading.Thread(target=time_constructions, args=(depths,))
+        t = threading.Thread(target=time_constructions, args=(depths,debug))
         t.start()
         threadlist.append(t)
     for t in threadlist:
         t.join()
-    print "All %d threads finished" % (nthreads,)
+    if debug:
+        print "All %d threads finished" % (nthreads,)
 
-def main(depths=DEFAULT_DEPTHS, threads=0):
-    print "Garbage Collector Test"
-    print " Stretching memory with a binary tree of depth %d" % kStretchTreeDepth
-    print_diagnostics()
-    t_start = time.time()
-    temp_tree = make_tree(kStretchTreeDepth)
-    temp_tree = None
+def main(numruns, depths=DEFAULT_DEPTHS, threads=0, debug=False):
+    times = []
+    for i in range(numruns):
+        if debug:
+            print "Garbage Collector Test"
+            print " Stretching memory with a binary tree of depth %d" % kStretchTreeDepth
+        print_diagnostics()
+        t_start = time.time()
+        temp_tree = make_tree(kStretchTreeDepth)
+        temp_tree = None
 
-    # Create a long lived object
-    print " Creating a long-lived binary tree of depth %d" % kLongLivedTreeDepth
-    long_lived_tree = Node()
-    populate(kLongLivedTreeDepth, long_lived_tree)
-
-    # Create long-lived array, filling half of it
-    print " Creating a long-lived array of %d doubles" % kArraySize
-    array = [0.0] * kArraySize
-    i = 1
-    while i < kArraySize/2:
-        array[i] = 1.0/i
-        i += 1
-    print_diagnostics()
+        # Create a long lived object
+        if debug:
+            print " Creating a long-lived binary tree of depth %d" % kLongLivedTreeDepth
+        long_lived_tree = Node()
+        populate(kLongLivedTreeDepth, long_lived_tree)
+
+        # Create long-lived array, filling half of it
+        if debug:
+            print " Creating a long-lived array of %d doubles" % kArraySize
+        array = [0.0] * kArraySize
+        i = 1
+        while i < kArraySize/2:
+            array[i] = 1.0/i
+            i += 1
+        print_diagnostics()
 
-    if threads:
-        time_parallel_constructions(depths, threads)
-    else:
-        time_constructions(depths)
+        if threads:
+            time_parallel_constructions(depths, threads, debug)
+        else:
+            time_constructions(depths, debug)
 
-    if long_lived_tree is None or array[1024] != 1.0/1024:
-        raise Failed
+        if long_lived_tree is None or array[1024] != 1.0/1024:
+            raise Failed
 
-    t_finish = time.time()
-    print_diagnostics()
-    print "Completed in %f ms." % ((t_finish-t_start)*1000.)
+        t_finish = time.time()
+        print_diagnostics()
+        if debug:
+            print "Completed in %f ms." % ((t_finish-t_start)*1000.)
+        times.append(t_finish - t_start)
+    return times
 
 class Failed(Exception):
     pass
@@ -170,35 +183,26 @@
     return 2
 
 def entry_point(argv):
-    depths = DEFAULT_DEPTHS
-    threads = 0
-    repeatcount = 1
-    for arg in argv[1:]:
-        if arg.startswith('--threads='):
-            arg = arg[len('--threads='):]
-            if not ENABLE_THREADS:
-                print "threads disabled (they cannot be translated)"
-                return 1
-            try:
-                threads = int(arg)
-            except ValueError:
-                return argerror()
-        elif arg.startswith('--depths='):
-            arg = arg[len('--depths='):].split(',')
-            try:
-                depths = [int(s) for s in arg]
-            except ValueError:
-                return argerror()
-        else:
-            try:
-                repeatcount = int(arg)
-            except ValueError:
-                return argerror()
-    for i in range(repeatcount):
-        main(depths, threads)
-    return 0
+    import optparse
+    import util
 
+    def parse_depths(option, opt_str, value, parser):
+        parser.values.depths = [v for v in value.split(',') if v]
+    
+    parser = optparse.OptionParser(
+        usage="%prog [options]",
+        description="Test the performance of the Telco decimal benchmark")
+    util.add_standard_options_to(parser)
+    parser.add_option('--threads', default=0, action="store",
+                      help="provide number of threads (default 1)")
+    parser.add_option('--depths', default=DEFAULT_DEPTHS, type="string",
+                      action="callback", callback=parse_depths,
+                      help='tree depths')
+    parser.add_option('--debug', default=False, action='store_true',
+                      help="enable debugging")
+    options, args = parser.parse_args(argv)
+    util.run_benchmark(options, options.num_runs, main,
+                       options.depths, options.threads, options.debug)
 
 if __name__ == '__main__':
-    import sys
-    sys.exit(entry_point(sys.argv))
+    entry_point(sys.argv[1:])



More information about the Pypy-commit mailing list