1. Pypy
  2. Untitled project
  3. pypy

Commits

Maciej Fijalkowski  committed 963843f

more of spring cleaning

  • Participants
  • Parent commits 7f44b55
  • Branches default

Comments (0)

Files changed (7)

File pypy/rpython/microbench/__init__.py

  • Ignore whitespace
Empty file removed.

File pypy/rpython/microbench/autopath.py

  • Ignore whitespace
-"""
-self cloning, automatic path configuration 
-
-copy this into any subdirectory of pypy from which scripts need 
-to be run, typically all of the test subdirs. 
-The idea is that any such script simply issues
-
-    import autopath
-
-and this will make sure that the parent directory containing "pypy"
-is in sys.path. 
-
-If you modify the master "autopath.py" version (in pypy/tool/autopath.py) 
-you can directly run it which will copy itself on all autopath.py files
-it finds under the pypy root directory. 
-
-This module always provides these attributes:
-
-    pypydir    pypy root directory path 
-    this_dir   directory where this autopath.py resides 
-
-"""
-
-def __dirinfo(part):
-    """ return (partdir, this_dir) and insert parent of partdir
-    into sys.path.  If the parent directories don't have the part
-    an EnvironmentError is raised."""
-
-    import sys, os
-    try:
-        head = this_dir = os.path.realpath(os.path.dirname(__file__))
-    except NameError:
-        head = this_dir = os.path.realpath(os.path.dirname(sys.argv[0]))
-
-    error = None
-    while head:
-        partdir = head
-        head, tail = os.path.split(head)
-        if tail == part:
-            checkfile = os.path.join(partdir, os.pardir, 'pypy', '__init__.py')
-            if not os.path.exists(checkfile):
-                error = "Cannot find %r" % (os.path.normpath(checkfile),)
-            break
-    else:
-        error = "Cannot find the parent directory %r of the path %r" % (
-            partdir, this_dir)
-    if not error:
-        # check for bogus end-of-line style (e.g. files checked out on
-        # Windows and moved to Unix)
-        f = open(__file__.replace('.pyc', '.py'), 'r')
-        data = f.read()
-        f.close()
-        if data.endswith('\r\n') or data.endswith('\r'):
-            error = ("Bad end-of-line style in the .py files. Typically "
-                     "caused by a zip file or a checkout done on Windows and "
-                     "moved to Unix or vice-versa.")
-    if error:
-        raise EnvironmentError("Invalid source tree - bogus checkout! " +
-                               error)
-    
-    pypy_root = os.path.join(head, '')
-    try:
-        sys.path.remove(head)
-    except ValueError:
-        pass
-    sys.path.insert(0, head)
-
-    munged = {}
-    for name, mod in sys.modules.items():
-        if '.' in name:
-            continue
-        fn = getattr(mod, '__file__', None)
-        if not isinstance(fn, str):
-            continue
-        newname = os.path.splitext(os.path.basename(fn))[0]
-        if not newname.startswith(part + '.'):
-            continue
-        path = os.path.join(os.path.dirname(os.path.realpath(fn)), '')
-        if path.startswith(pypy_root) and newname != part:
-            modpaths = os.path.normpath(path[len(pypy_root):]).split(os.sep)
-            if newname != '__init__':
-                modpaths.append(newname)
-            modpath = '.'.join(modpaths)
-            if modpath not in sys.modules:
-                munged[modpath] = mod
-
-    for name, mod in munged.iteritems():
-        if name not in sys.modules:
-            sys.modules[name] = mod
-        if '.' in name:
-            prename = name[:name.rfind('.')]
-            postname = name[len(prename)+1:]
-            if prename not in sys.modules:
-                __import__(prename)
-                if not hasattr(sys.modules[prename], postname):
-                    setattr(sys.modules[prename], postname, mod)
-
-    return partdir, this_dir
-
-def __clone():
-    """ clone master version of autopath.py into all subdirs """
-    from os.path import join, walk
-    if not this_dir.endswith(join('pypy','tool')):
-        raise EnvironmentError("can only clone master version "
-                               "'%s'" % join(pypydir, 'tool',_myname))
-
-
-    def sync_walker(arg, dirname, fnames):
-        if _myname in fnames:
-            fn = join(dirname, _myname)
-            f = open(fn, 'rwb+')
-            try:
-                if f.read() == arg:
-                    print "checkok", fn
-                else:
-                    print "syncing", fn
-                    f = open(fn, 'w')
-                    f.write(arg)
-            finally:
-                f.close()
-    s = open(join(pypydir, 'tool', _myname), 'rb').read()
-    walk(pypydir, sync_walker, s)
-
-_myname = 'autopath.py'
-
-# set guaranteed attributes
-
-pypydir, this_dir = __dirinfo('pypy')
-
-if __name__ == '__main__':
-    __clone()

File pypy/rpython/microbench/dict.py

  • Ignore whitespace
-from pypy.rpython.microbench.microbench import MetaBench
-
-class str_dict__set_item:
-    __metaclass__ = MetaBench
-
-    def init():
-        return {}
-    args = ['obj', 'i']
-    def loop(obj, i):
-        obj['foo'] = i
-        obj['bar'] = i
-
-class str_dict__get_item:
-    __metaclass__ = MetaBench
-
-    def init():
-        return {'foo': 0, 'bar': 1}
-    args = ['obj', 'i']
-    def loop(obj, i):
-        return obj['foo'] + obj['bar']
-
-class int_dict__set_item:
-    __metaclass__ = MetaBench
-
-    def init():
-        return {}
-    args = ['obj', 'i']
-    def loop(obj, i):
-        obj[42] = i
-        obj[43] = i
-
-class int_dict__get_item:
-    __metaclass__ = MetaBench
-
-    def init():
-        return {42: 0, 43: 1}
-    args = ['obj', 'i']
-    def loop(obj, i):
-        return obj[42] + obj[43]
-
-
-class Foo:
-    pass
-
-obj1 = Foo()
-obj2 = Foo()
-
-class obj_dict__set_item:
-    __metaclass__ = MetaBench
-
-    def init():
-        return {}
-    args = ['obj', 'i']
-    def loop(obj, i):
-        obj[obj1] = i
-        obj[obj2] = i
-
-class obj_dict__get_item:
-    __metaclass__ = MetaBench
-
-    def init():
-        return {obj1: 0, obj2: 1}
-    args = ['obj', 'i']
-    def loop(obj, i):
-        return obj[obj1] + obj[obj2]

File pypy/rpython/microbench/indirect.py

  • Ignore whitespace
-from pypy.rpython.microbench.microbench import MetaBench
-
-def f1(x):
-    return x
-
-def f2(x):
-    return x+1
-
-def f3(x):
-    return x+2
-
-def f4(x):
-    return x+3
-
-FUNCS = [f1, f2, f3, f4]
-
-class indirect__call:
-    __metaclass__ = MetaBench
-
-    def init():
-        return FUNCS
-    args = ['obj', 'i']
-    def loop(obj, i):
-        return obj[i%4](i)

File pypy/rpython/microbench/list.py

  • Ignore whitespace
-from pypy.rpython.microbench.microbench import MetaBench
-
-class list__append:
-    __metaclass__ = MetaBench
-    def init():
-        return []
-    args = ['obj', 'i']
-    def loop(obj, i):
-        obj.append(i)
-    
-class list__get_item:
-    __metaclass__ = MetaBench
-    LOOPS = 100000000
-    def init():
-        obj = []
-        for i in xrange(1000):
-            obj.append(i)
-        return obj
-    args = ['obj', 'i']
-    def loop(obj, i):
-        return obj[i%1000]
-
-class list__set_item:
-    __metaclass__ = MetaBench
-    LOOPS = 100000000
-    def init():
-        obj = []
-        for i in xrange(1000):
-            obj.append(i)
-        return obj
-    args = ['obj', 'i']
-    def loop(obj, i):
-        obj[i%1000] = i
-
-class fixed_list__get_item:
-    __metaclass__ = MetaBench
-    LOOPS = 100000000
-    def init():
-        return [0] * 1000
-    args = ['obj', 'i']
-    def loop(obj, i):
-        return obj[i%1000]
-
-class fixed_list__set_item:
-    __metaclass__ = MetaBench
-    LOOPS = 100000000
-    def init():
-        return [0] * 1000
-    args = ['obj', 'i']
-    def loop(obj, i):
-        obj[i%1000] = i
-
-class list__iteration__int:
-    __metaclass__ = MetaBench
-    LOOPS = 100000
-    def init():
-        obj = [0]*1000
-        obj[0] = 42
-        return obj
-    args = ['obj']
-    def loop(obj):
-        tot = 0
-        for item in obj:
-            tot += item
-        return tot
-
-class list__iteration__string:
-    __metaclass__ = MetaBench
-    LOOPS = 100000
-    def init():
-        obj = ['foo']*1000
-        obj[0] = 'bar'
-        return obj
-    args = ['obj']
-    def loop(obj):
-        tot = 0
-        for item in obj:
-            tot += len(item)
-        return tot

File pypy/rpython/microbench/microbench.py

  • Ignore whitespace
-#!/usr/bin/env python
-
-import sys
-import autopath
-from time import clock
-import subprocess
-from pypy.translator.interactive import Translation
-
-LOOPS = 10000000
-
-class MetaBench(type):
-    def __new__(self, cls_name, bases, cls_dict):
-        loop = cls_dict['loop']
-        loop._dont_inline_ = True
-        myglob = {
-            'init': cls_dict['init'],
-            'loop': loop,
-            'LOOPS': cls_dict.get('LOOPS', LOOPS),
-            'clock': clock,
-            }
-        args = ', '.join(cls_dict['args'])
-        source = """
-def %(cls_name)s():
-    obj = init()
-    start = clock()
-    for i in xrange(LOOPS):
-        loop(%(args)s)
-    return clock() - start
-""" % locals()
-        exec source in myglob
-        func = myglob[cls_name]
-        func.benchmark = True
-        return func
-
-
-def run_benchmark(exe):
-    from pypy.translator.cli.test.runtest import CliFunctionWrapper
-    from pypy.translator.jvm.test.runtest import JvmGeneratedSourceWrapper
-    
-    if exe.__class__ in [CliFunctionWrapper,JvmGeneratedSourceWrapper]:
-        stdout, stderr, retval = exe.run()
-    else:
-        assert isinstance(exe, str)
-        bench = subprocess.Popen(exe, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
-        stdout, stderr = bench.communicate()
-        retval = bench.wait()
-    
-    if retval != 0:
-        print 'Running benchmark failed'
-        print 'Standard Output:'
-        print stdout
-        print '-' * 40
-        print 'Standard Error:'
-        print stderr
-        raise SystemExit(-1)
-    
-    mydict = {}
-    for line in stdout.splitlines():
-        name, res = line.split(':')
-        mydict[name.strip()] = float(res)
-    return mydict
-
-def import_benchmarks():
-    modules = sys.argv[1:]
-    if len(modules) == 0:
-        # import all the microbenchs
-        from glob import glob
-        for module in glob('*.py'):
-            if module not in ('__init__.py', 'autopath.py', 'microbench.py'):
-                modules.append(module)
-    
-    for module in modules:
-        module = module.rstrip('.py')
-        exec 'from %s import *' % module in globals()
-
-def main():
-    import_benchmarks()
-    benchmarks = []
-    for name, thing in globals().iteritems():
-        if getattr(thing, 'benchmark', False):
-            benchmarks.append((name, thing))
-    benchmarks.sort()
-    
-    def entry_point(argv):
-        for name, func in benchmarks:
-            print name, ':', func()
-        return 0
-    
-    t = Translation(entry_point, standalone=True, backend='c')
-    c_exe = t.compile()
-    t = Translation(entry_point, standalone=True, backend='cli')
-    cli_exe = t.compile()
-    t = Translation(entry_point, standalone=True, backend='jvm')
-    jvm_exe = t.compile()
-  
-    c_res = run_benchmark(c_exe)
-    cli_res = run_benchmark(cli_exe)
-    jvm_res = run_benchmark(jvm_exe)
-    
-    print 'benchmark                              genc     gencli     cli_ratio   genjvm     jvm_ratio'
-    print
-    for name, _ in benchmarks:
-        c_time = c_res[name]
-        cli_time = cli_res[name]
-        jvm_time = jvm_res[name]
-        if c_time == 0:
-            cli_ratio = '%10s' % '---'
-        else:
-            cli_ratio = '%10.2f' % (cli_time/c_time)
-        if c_time == 0:
-            jvm_ratio = '%10s' % '---'
-        else:
-            jvm_ratio = '%10.2f' % (jvm_time/c_time)
-        print '%-32s %10.2f %10.2f %s %10.2f %s' % (name, c_time, cli_time, cli_ratio, jvm_time, jvm_ratio)
-
-if __name__ == '__main__':
-    main()

File pypy/rpython/microbench/rdict.py

  • Ignore whitespace
-from pypy.rlib.objectmodel import r_dict
-from pypy.rpython.microbench.microbench import MetaBench
-
-class Obj:
-    def __init__(self, x):
-        self.x = x
-
-def myhash(obj):
-    return obj.x
-
-def mycmp(obj1, obj2):
-    return obj1.x == obj2.x
-
-class Space:
-    def myhash(self, obj):
-        return obj.x
-
-    def mycmp(self, obj1, obj2):
-        return obj1.x == obj2.x
-
-    def _freeze_(self):
-        return True
-
-space = Space()
-obj1 = Obj(1)
-obj2 = Obj(2)
-
-class r_dict__set_item:
-    __metaclass__ = MetaBench
-
-    def init():
-        return r_dict(mycmp, myhash)
-    args = ['obj', 'i']
-    def loop(obj, i):
-        obj[obj1] = i
-        obj[obj2] = i
-
-class r_dict__get_item:
-    __metaclass__ = MetaBench
-
-    def init():
-        res = r_dict(mycmp, myhash)
-        res[obj1] = 42
-        res[obj2] = 43
-        return res
-    args = ['obj', 'i']
-    def loop(obj, i):
-        return obj[obj1] + obj[obj2]
-
-class r_dict__frozen_pbc__set_item:
-    __metaclass__ = MetaBench
-
-    def init():
-        return r_dict(space.mycmp, space.myhash)
-    args = ['obj', 'i']
-    def loop(obj, i):
-        obj[obj1] = i
-        obj[obj2] = i
-
-class r_dict__frozen_pbc__get_item:
-    __metaclass__ = MetaBench
-
-    def init():
-        res = r_dict(space.mycmp, space.myhash)
-        res[obj1] = 42
-        res[obj2] = 43
-        return res
-    args = ['obj', 'i']
-    def loop(obj, i):
-        return obj[obj1] + obj[obj2]