6
from py.compat import subprocess
7
from pypy.translator.interactive import Translation
11
class MetaBench(type):
12
def __new__(self, cls_name, bases, cls_dict):
13
loop = cls_dict['loop']
14
loop.dont_inline = True
16
'init': cls_dict['init'],
18
'LOOPS': cls_dict.get('LOOPS', LOOPS),
21
args = ', '.join(cls_dict['args'])
26
for i in xrange(LOOPS):
28
return clock() - start
31
func = myglob[cls_name]
36
def run_benchmark(exe):
37
from pypy.translator.cli.test.runtest import CliFunctionWrapper
38
if isinstance(exe, CliFunctionWrapper):
39
stdout, stderr, retval = exe.run()
41
assert isinstance(exe, str)
42
bench = subprocess.Popen(exe, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
43
stdout, stderr = bench.communicate()
47
print 'Running benchmark failed'
48
print 'Standard Output:'
51
print 'Standard Error:'
56
for line in stdout.splitlines():
57
name, res = line.split(':')
58
mydict[name.strip()] = float(res)
61
def import_benchmarks():
62
modules = sys.argv[1:]
64
# import all the microbenchs
66
for module in glob('*.py'):
67
if module not in ('__init__.py', 'autopath.py', 'microbench.py'):
68
modules.append(module)
70
for module in modules:
71
module = module.rstrip('.py')
72
exec 'from %s import *' % module in globals()
77
for name, thing in globals().iteritems():
78
if getattr(thing, 'benchmark', False):
79
benchmarks.append((name, thing))
82
def entry_point(argv):
83
for name, func in benchmarks:
84
print name, ':', func()
87
t = Translation(entry_point, standalone=True, backend='c')
89
t = Translation(entry_point, standalone=True, backend='cli')
92
c_res = run_benchmark(c_exe)
93
cli_res = run_benchmark(cli_exe)
95
print 'benchmark genc gencli ratio'
97
for name, _ in benchmarks:
99
cli_time = cli_res[name]
101
ratio = '%10s' % '---'
103
ratio = '%10.2f' % (cli_time/c_time)
104
print '%-32s %10.2f %10.2f %s' % (name, c_time, cli_time, ratio)
106
if __name__ == '__main__':