[pypy-svn] r50242 - pypy/dist/pypy/translator/microbench
pedronis at codespeak.net
pedronis at codespeak.net
Tue Jan 1 15:26:00 CET 2008
Author: pedronis
Date: Tue Jan 1 15:26:00 2008
New Revision: 50242
Modified:
pypy/dist/pypy/translator/microbench/microbench.py
pypy/dist/pypy/translator/microbench/test_dispatch.py
Log:
with these changes the microbenchs run out of the box on top of a recent Jython if given enough java heap.
test_disaptch_nop cannot be run there though.
Modified: pypy/dist/pypy/translator/microbench/microbench.py
==============================================================================
--- pypy/dist/pypy/translator/microbench/microbench.py (original)
+++ pypy/dist/pypy/translator/microbench/microbench.py Tue Jan 1 15:26:00 2008
@@ -4,7 +4,18 @@
implementations on a set of microbenchmarks. The script usally is started
with "./microbench.py python ./pypy" where pypy is a symlink to you pypy exectable."""
-import os, time, sys, gc
+import os, time, sys
+
+try:
+ import gc
+except ImportError:
+ if sys.platform.startswith('java'):
+ import java.lang
+ gccollect = java.lang.System.gc
+ else:
+ gccollect = lambda: None
+else:
+ gccollect = gc.collect
try:
this_dir = os.path.dirname(__file__)
@@ -18,7 +29,7 @@
microbench = fname[:-3]
microbenches.append(microbench)
-def run(test_cases):
+def run(test_cases, fmt):
MINIMUM_MICROBENCH_TIME = 1.0
for microbench in microbenches:
@@ -33,7 +44,7 @@
continue
testcase_name = microbench + '.' + k + '()'
testcase = testmoddict[k]
- gc.collect()
+ gccollect()
start = time.clock()
n = 0
duration = 0.0
@@ -41,10 +52,16 @@
testcase()
n += 1
duration = time.clock() - start
- print '%s took %.2f seconds' % (testcase_name, duration / float(n))
+ print ('%s took ' + fmt +' seconds') % (testcase_name, duration / float(n))
if __name__ == '__main__':
args = sys.argv[1:]
+ if args[0].startswith('-F'):
+ fmt = "%" + args[0][2:]
+ args.pop(0)
+ else:
+ fmt = "%.2f"
+
if '-k' in args:
i = args.index('-k')
executables = args[:i]
@@ -57,7 +74,7 @@
for n, exe in enumerate(executables):
print 'exe:', exe
- data = [s for s in os.popen(exe + ' microbench.py %s 2>&1' % limit).readlines() if not s.startswith('debug:')]
+ data = [s for s in os.popen(exe + ' microbench.py -Fr %s 2>&1' % limit).readlines() if not s.startswith('debug:')]
benchdata = {}
for d in data:
try:
@@ -78,4 +95,4 @@
print '%5.2fx slower on %s' % (slowdown, testcase)
if not executables:
- run(test_cases)
+ run(test_cases, fmt)
Modified: pypy/dist/pypy/translator/microbench/test_dispatch.py
==============================================================================
--- pypy/dist/pypy/translator/microbench/test_dispatch.py (original)
+++ pypy/dist/pypy/translator/microbench/test_dispatch.py Tue Jan 1 15:26:00 2008
@@ -1,31 +1,36 @@
-import new, dis, sys
+try:
+ import dis
+except ImportError:
+ pass
+else:
+ import new, sys
-N_NOPS = 10**7
-N = int(50)
+ N_NOPS = 10**7
+ N = int(50)
-codestr = ""
-ccode = compile(codestr, '<string>', 'exec')
-mycode = N_NOPS * chr(dis.opmap['NOP']) + ccode.co_code
-co = new.code(ccode.co_argcount,
- ccode.co_nlocals,
- ccode.co_stacksize,
- ccode.co_flags,
- mycode,
- ccode.co_consts,
- ccode.co_names,
- ccode.co_varnames,
- ccode.co_filename,
- ccode.co_name,
- ccode.co_firstlineno,
- ccode.co_lnotab,
- ccode.co_freevars,
- ccode.co_cellvars)
+ codestr = ""
+ ccode = compile(codestr, '<string>', 'exec')
+ mycode = N_NOPS * chr(dis.opmap['NOP']) + ccode.co_code
+ co = new.code(ccode.co_argcount,
+ ccode.co_nlocals,
+ ccode.co_stacksize,
+ ccode.co_flags,
+ mycode,
+ ccode.co_consts,
+ ccode.co_names,
+ ccode.co_varnames,
+ ccode.co_filename,
+ ccode.co_name,
+ ccode.co_firstlineno,
+ ccode.co_lnotab,
+ ccode.co_freevars,
+ ccode.co_cellvars)
-def test_dispatch_nop():
- x = 0
- n = N
- while x < n:
- exec co
- x += 1
- #sys.stdout.write('.')
- #sys.stdout.flush()
+ def test_dispatch_nop():
+ x = 0
+ n = N
+ while x < n:
+ exec co
+ x += 1
+ #sys.stdout.write('.')
+ #sys.stdout.flush()
More information about the pypy-svn
mailing list