[pypy-svn] r27757 - pypy/dist/pypy/translator/goal

arigo at codespeak.net arigo at codespeak.net
Sat May 27 12:34:38 CEST 2006


Author: arigo
Date: Sat May 27 12:34:37 2006
New Revision: 27757

Added:
   pypy/dist/pypy/translator/goal/targetvarsized.py   (contents, props changed)
Modified:
   pypy/dist/pypy/translator/goal/translate.py
Log:
Added a target of variable size: it is built by exec'ing richards.py
as many times as specified on the command line.  Try:
    
    python translate.py targetvarsized.py 5



Added: pypy/dist/pypy/translator/goal/targetvarsized.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/translator/goal/targetvarsized.py	Sat May 27 12:34:37 2006
@@ -0,0 +1,60 @@
+import os, sys
+#from pypy.translator.goal import richards
+
+modfilename = os.path.join(os.path.dirname(__file__), 'richards.py')
+
+
+# Number of times richards is imported in parallel.
+# Can be changed on the command line, e.g.
+#
+#     translate.py targetvarsized.py 20
+#
+DEFAULT_CODE_SIZE_FACTOR   = 10
+
+
+# __________  Entry point  __________
+
+def richards_main(fn, iterations):
+    s = "Richards benchmark (RPython) starting...\n"
+    os.write(1, s)
+    result, startTime, endTime = fn(iterations)
+    if not result:
+        os.write(2, "Incorrect results!\n")
+        return False
+    os.write(1, "finished.\n")
+    total_s = endTime - startTime
+    avg = total_s * 1000 / iterations
+    os.write(1, "Total time for %d iterations: %f secs\n" %(iterations, total_s))
+    os.write(1, "Average time per iteration: %f ms\n" %(avg))
+    return True
+
+
+def entry_point(argv):
+    for fn in functions:
+        if not richards_main(fn, 10):
+            return 1
+    return 0
+
+# _____ Define and setup target ___
+
+def target(driver, args):
+    global modules, functions
+    if len(args) == 0:
+        N = DEFAULT_CODE_SIZE_FACTOR
+    elif len(args) == 1:
+        N = int(args[0])
+    else:
+        raise ValueError("too many command-line arguments")
+
+    modules = []
+    functions = []
+    f = open(modfilename)
+    source = f.read()
+    f.close()
+    for i in range(N):
+        d = {'__name__': 'richards%d' % i}
+        exec source in d
+        modules.append(d)
+        functions.append(d['entry_point'])
+
+    return entry_point, None

Modified: pypy/dist/pypy/translator/goal/translate.py
==============================================================================
--- pypy/dist/pypy/translator/goal/translate.py	(original)
+++ pypy/dist/pypy/translator/goal/translate.py	Sat May 27 12:34:37 2006
@@ -159,6 +159,7 @@
     thismod = sys.modules[__name__]
     targetspec_dic = {
         '__name__': os.path.splitext(os.path.basename(targetspec))[0],
+        '__file__': targetspec,
         'translate': thismod}
     sys.path.insert(0, os.path.dirname(targetspec))
     execfile(targetspec, targetspec_dic)



More information about the Pypy-commit mailing list